android - Is it possible to call method in Activity class from Application class? -


i have defined public method in activity class (lets some_method()).is possible call method in application class.

you can use singleton activity this:

public class youractivity extends appcompatactivity {  public static youractivity instance;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_layout);      instance=this;      //your code  }  //your method public void yourmethod() {  }  @override protected void ondestroy() {     super.ondestroy();     instance=null; }  } 

then in application method can call method of activity this:

if (youractivity.instance != null) {     youractivity.instance.yourmethod(); } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -