Accessing public methods of Activity
I am new to android development and have a confusion that if an ac开发者_如何学Gotivity( a class extends Activity) has some public methods, can we access these public methods outside that activity.
Regards, Waneya Iqbal
Yes. public methods are... public. This means that they're accessible from anywhere.
Read http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
Yes, you may. Activities are just like any other classes in Java.
Yet, you should be careful where and when do you call them, since they might not be exist or not in correct state at a specific time.
Not sure of what you want to achieve, but yes you can pass a reference of the activity to the caller, just as you would with any object, and call its public methods.
精彩评论