How Do I Call A Java Methods From One Class To Another Class In Android Development?
I have two classes which extend Activity and need to call another class method on main class on android development. I did something like subclass sub = new subclass(). It did not
Solution 1:
May i know why you would want to do so? If that method is so important to both of the classes, then create it inside a helper class (Which doesn't extend Activity) and create an object of it in both the classes, then with that object access that method.
Solution 2:
SubClass sub=new SubClass();
is creating an object of class SubClass
.
It is not a method calling.
enter code here
If the method is defined in class SubClass then you can call it by using its object and dot operator.
sub.MethodName();
Solution 3:
Try just to label the required method as static. But remember that in that case the called method should not depends on any non-static member variables of methods of the class.
Post a Comment for "How Do I Call A Java Methods From One Class To Another Class In Android Development?"