I create methodAbc() for getting network information. Context is required in this method.
I want to use this method for 3 Activities.
How can I implement it?
I create methodAbc() for getting network information. Context is required in this method.
I want to use this method for 3 Activities.
How can I implement it?
There is two option right now i can see.
BaseActivity which will consist the method .. all the activities will extend from BaseActivityContext as parameterYou can always access a public method from any class. You just have to create an instance of that class, and then call the method on that instance. For example:
public void methodAbc(Context c) {
// do stuff
}
and then reference that method like so:
YourClass x = new YourClass(yourClassParameters);
x.methodAbc(yourContext); // yourContext might be getApplicationContext()
That, or you could make the method static. Although, you may not be able to make your method static if it has calls to other non-static class methods. Assuming that it can be made a static method, though:
public static void methodAbc(Context c) {
// do stuff
}
and then you can call it from another class, like this:
YourClass.methodAbc(yourContext); // yourContext might be getApplicationContext()
public void myMethod(Context context) {
//etc etc
}
Now from any class just refer to it as MyClass.myMethod(this);