Hi I have an activity named BaseActivity, which extends Activity.
from this i have to go to SettingsActivity which extends PreferenceActivity
, on menu button press. To start a AsyncTask
, which is in an independent class, i need an instance of BaseActivity
. How can i get a BaseActivity
instance in the SettingsActivity
?
is there any way like, eg:
intent.putExtra("activity_instance",BaseActivity.this);
Make a static Context in "Base Activity"
and in your "PreferenceActivity" activity use this way
You are confusing activities with class objects. The moment activity class is instantiated it obeys all activity life cycle rules, importantly system can kill this activity any time. So you have to design activities in such a way that it shouldn't be dependent on another activity instance at all but only drive the results. you can write a helper class and call it again and again if you want. if not use storages like sdcard or preference or sandbox to store the information and retrieve it from the other activity. If you want to keep some of these information in memory then subclass Application class and keep them at the application level.
Use getters and setters and make the class they reside as singleton class.
This is a singleton class.Using this class we can share data(ex: int,boolean,activity instance ...etc) all over the class.
In BaseActivity class do like this.
In SettingsActivity do like this
please give tick if this works