im having issues with whatsapp:// url scheme - java

method does not override method from superclass. how can i fix this error.
im making and android native app for my website.and my website contain a button which amy app defining as unknown url error so i add the code (shared in screenshote) but after that is showing a error and its not working, im doing making this app without any pre knowledge of java or android app development please help me out to solve this issue . everything is working fine instead of whatsapp url

With this code, you're saying that there is a method shouldOverrideUrlLoading in your superclass.
Superclass is the class you extend. Example:
public class MainActivity extends ExampleClass { }
To override a method, there needs to be a
protected void shouldOverrideUrlLoading(){ }
method in ExampleClass.
If you didn't override any class, remove #Override.
If you did and must extend a class, you can't go further without inheritance knowledge.

MainActivity and this superclass not has shouldOverrideUrlLoading method

Related

Stripe - android java

I'm integrating stripe in android java. Can anyone help me sample stripe code in java.
As I'm new to kotlin.
Using default stripe classfor add card "PaymentMethodsActivityStarter"
I'm unable to get response in onActivityResult
You must look at the code carefully, analyze it and then proceed. If you concentrate, it will become simple for you in no time. Let's go through an example:
class MyApp : Application() {
We know that this is a class, and its name is MyApp. A quick Google search would tell you that the : here just means that the class is extending whatever's on the right of it. Therefore the corresponding Java code should be
public class MyApp extends Application {
Now we go to the next line
override fun onCreate() {
States that an override tag is involved - a method is being overridden. fun in Kotlin means the following should be a function name. Once again, a Google search away. We see that it has no parameters, and no returns. Now you can make the Java code
#Override
public void onCreate() {
Now we move on
super.onCreate()
Which is calling the superclass method, same in Java.
PaymentConfiguration.init(applicationContext,"pk_test_TYooMQauvdEDq54NiTphI7jx")
I'm not familiar with Kotlin, but I can see that some form of init is being called. Parameters are a Context of some sort and a String. A Google search told me that init is basically calling the consturctor of a class. Therefore I can immediately try out
new PaymentConfiguration(getApplicationContext(), "pk_test_TYooMQauvdEDq54NiTphI7jx");
If that doesn't work, then Google more to understand what the code means instead of searching for a specific Java equivalent. If you still have problems, then post on here again with examples and some code and include the solutions you have tried and offer thoughts on what you think the issue could be. This is how we become better programmers that can adapt to and overcome problems.

Unexpected results from implementing an AAR library compared to source library in Android Projects

Summary
Current Behavior
Unexpected results from implementing an AAR library compared to source library in Android Projects.
super keyword seems to be point to a grandparent class rather than the direct parent class.
Somehow overridding a grandparent method even though same method is declared and overridden in parent.
Both issues only exist when using a compiled AAR of library, i.e. problem does not exist when implementing same project using library source code.
Expected Behavior
I would expect both calls to super to resolve to parent class.
I would expect overriding onCreate to override the method in parent class not grandparent.
Working App
I have an Android Application based in package com.example.sourceapp
This uses and manages the source code for a separate library located in com.example.sourcelibrary, in which is a class we'll call ParentClass.
In ParentClass I have two members of interest.
A public boolean called myBool which originates in ParentClass
An method overriding the android.app.Activity.onCreate method which is also overridden and inherited from some grandparent class GrandparentClass in some other library com.example.someotherlibrary.
In my com.example.sourceapp.MainActivity I do two things.
I extend com.example.sourcelibrary.ParentClass and modify myBool contained within the ParentClass using super.myBool = true;.
I call onCreate via super.onCreate() within the overridden method.
Both work as expected. When I hover over super.onCreate Android Studio indicates it to resolve properly to the parent class as expected.
Not Working App
In a different Android Project com.example.compiledapp.MainActivity instead of depending on the source library com.example.sourcelibrary, I depend on a compiled (debug) AAR file made from the same library.
I import the needed class from the AAR package at the top of com.example.compiledapp.MainActivity with import com.example.sourcelibrary.ParentClass without any resolution issue.
Later in com.example.compiledapp.MainActivity I use the same code as before to
super.myBool = true;
super.onCreate()
but Android Studio indicates that it cannot resolve myBool in super.myBool = true;.
Furthermore, the 2nd line seems to resolve just fine, but upon closer inspection when I hover over it, Android Studio indicates that onCreate resolves to being a member of the grandparent class com.example.someotherlibrary.GrandparentClass instead of the parent class com.example.sourcelibrary.ParentClass.
Looking a few lines up, as I hover over the onCreate override, Android Studio indicates that I am overriding the onCreate from the grandparent class, not the parent class.
Why/How would onCreate skip the parent method and override the grandparent class?
Also it looks like the super keyword is resolving to the grandparent class rather than to the parent class. That is the only explanation I can think of that would result in onCreate resolving to the GrandparentClass and myBool not being resolvable. I didn't think this was how super worked.
Is this normal and I simply am misunderstanding something fundamental about inheritance? Maybe I am doing something wrong when compiling to AAR such that the parent variables/methods become inaccessible despite being declared public? Or maybe Android Studio gives preference to one package over another based on some rules I am unaware of?
Working Code
package com.example.sourceapp;
import android.os.Bundle;
import com.example.sourcelibrary.ParentClass;
public class MainActivity extends ParentClass {
// Shows to Override onCreate in ParentClass
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super resolves to ParentClass
super.myBool = true; // super resolves to ParentClass
}
}
Not Working Code
package com.example.compiledapp;
import android.os.Bundle;
import com.example.sourcelibrary.ParentClass;
public class MainActivity extends ParentClass {
// Shows to Override onCreate in GrandparentClass
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // super resolves to Grandparent
super.myBool = true; // does not resolve
}
}
I ended up tracking down the error. It turns out when building my com.example.sourceapp, which included the library module com.example.sourcelibrary, the build process was not updating the AAR file, and there was apparently something wrong/old in the outdated sourcelibrary code (maybe it was missing the onCreate method and myBool. Not sure really as I don't recall where in my git history it would have been since I only briefly noted the modified date was old, then rebuilt and the old timestamp is now gone.
Regardless, what helped was going to the gradle menu in Android Studio for the com.example.sourceapp and navigating to the sourcelibrary-->Tasks-->build-->build. Attempting to build the library directly threw an error related to SDK versions, so I fixed this and rebuilt, reimported to the compiledapp and it worked as expected.
The thing others may learn from this, is that if something strange is occurring with your AAR dependency, check that the source code you are building the AAR from is actually building and updating the AAR file, as Android Studio apparently doesn't throw an error when building the app that surrounds the library.
Maybe the SDK settings in the app level gradle overrode the library level gradle settings and allowed it to build the app without errors, and the updated library was actually built, but only within the APK? Not sure, exactly why, but at least an overall lesson was learned.

How do I call a method in LibGDX in the "AndroidLauncher" class?

Is there a possibility in LibGDX to call methods in the "AndroidLauncher" class, have tried quite a lot but it does not go.
I hope someone can give me an answer.
Bye
Hopefully you're trying to call method of AndroidLauncher class which is in android module.
You can do this by interfacing, try this
https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code

Getting Data inside a fragment from Activity

I am working with Android Fragments pretty extensively and one of the problems I am having is the lack of proper mechanism to pass complex objects to it.
In the android developers documentation for Fragments, they have a static method called newInstance called with some simple arguments which will be packaged into a Bundle and used inside the Fragment. However this method cannot be employed for passing complex objects.
Because I have been using the Fragments api a lot, it is becoming more and more important to have complex objects passed to it. One way to do this is by implementing the Parcelable interface, which I don't want to do for all the classes.
So, I thought I could do this :
Define an interface like this in the Fragment:
// Container Activity must implement this interface
public interface ReceiveDataInterface {
public MyClass getData(uniqueFragmentID);
}
Force the Activities using this fragment to implement the interface and call ReceiveDataInterface.getData(getArgument.getString(UNIQUEID))
In the Activity instantiate fragment using the newInstance method by passing a uniqueFragmentID and implement the ReceiveDataInterface which gives data based on uniqueFragmentID.
Is it a good idea to do this? if not, why? and how should I go about doing this?
Note:This is done in the same lines as OnArticleSelectedListener described in the documentation.
Any help is much appreciated.
We use this approach for any app we build for android. It works well. I havent tested every method of doing this, but i think this is among the best way.
Another approach would be to make the Fragment themselves independent. Why not write the code that fetches data from network/database in the Fragment itself?

Is there anything wrong with using a public static Context? ( Regarding getResources() )

Recently I ran into a problem when trying to load an bitmap outside of my main class. I found that within my main class I could pass this as a Context to any given function allowing me to call getResources() from within that function. There are a couple of things about this which don't make sense to me.
The keyword "this" simply refers to the current object the function is running in, right? If so, how can I pass my main class as a Context by using "this"? It doesn't even have a Context in it. I am using "extends Activity", but Activity doesn't seem to contain any function called getResources() in it either.
I found a workaround which allows me to do what I want a bit easier which is to declare a public static Context appContext; within my main class. Then, within onCreate() I set appContext = this; Then, from elsewhere I can call MainActivity.appContext.getResources() whenever I need it. So, I really have a few questions here.
Why are MainActivity(my main class) and appContext not essentially the same thing when appContext is set to "this" from inside MainActivity (There is no such thing as MainActivity.getResources())
Is this unsafe to do? Could this cause any potential problems in my program?
Is there a way to load images without having to use getResources()?
What is the proper way to show my code in this website? The standard I am used to ([code][/code] tags) don't seem to work properly in the preview, so I am assuming it is handled differently here. The formatting help page says to simply use four spaces, but that doesn't seem to show any difference in the preview section either.
EDIT:
I just read in another thread somebody said
now everything depends on your main activity's onCreate method having been called.
That got me thinking. Under what circumstances would onCreate not be called? It seems like if it wasn't called the program would stop working properly in many ways not related to having a static variable initialized inside it(ie. setContentView would not be called).
So assuming that there is nothing wrong with doing it this way, the only drawback I can find, is that "MainActivity.appContext.getResources()" is a lot to type to call a function. Is there any way to create a sort of alias for this? I suppose I could create a function which simply calls that, but that just seems silly.
If you look here you see that activity is a subclass of Context.
You can format code with a backtic, or just use the {} buttons on the editor. See the markdown manual for more info.

Categories