Android How to get Last Focused Activity after "Force Stop" the Application

Go To StackoverFlow.com

0

I am developing android Application having number of activities. The requirement of the application is When i "FORCESTOP" the application manually(Settings->Applications->ManageApplication->APP_NAME->FORCESTOP), the last focused activity(UI Page) to be displayed. Can i get the Last focused Activity after *FORCESTOP*ing the Application? Please help me with the sample code.

2012-04-04 07:58
by Avadhani Y


1

You should keep track of each activity change and save it to file (e.g. in your sharedpreferences) immediately when the change happens. Something like this

protected void onResume() {
    SharedPreferences.Editor edit =  PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).edit();
    edit.putString("LastActiveActivity", this.getClass().getName());
    edit.commit();
    super.onResume();
}

Make sure you save the current activity in the onResume() method of all your activities.

When you restart you can read the last activity back from your preferences. This should be done in the onCreate() method of your main activity (the one that is specified as "LAUNCHER" in your manifest). Then start the activity with the name you've read back.

2012-04-04 10:55
by THelper
Ads