Resume After App Kill Android
I am designing an Android App. My aim is that if the App is killed while it was in the background, and if the user starts the app again then it should have the option to resume th
Solution 1:
You can use shared preferences for tasks like these.
In your onStop() function, set a flag in shared preferences like:
SharedPreferences.Editoreditor= getPreferences(MODE_PRIVATE).edit();
editor.putString("killed", "yes");
In your onStart(), retrieve the preference and check it like this:
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
String flag = prefs.getString("killed", null);
if(flag!=null && flag.equals("yes")
{
//activity is resumed
}
else
{
//activity is started from scratch
}
for more info on shared preferences, see official docs here: http://developer.android.com/guide/topics/data/data-storage.html#pref
Solution 2:
What you can do.Create a Shared Preference variable inside onDestroy method
And check of the variable if it is present .On resuming the previous state it wont be present.It will be present only when the activity is being destroyed
Post a Comment for "Resume After App Kill Android"