How to know in settings "Don't keep activities" option is enabled in ics via code. If it is in enabled,how to prevent the activity.
Note: I have used more activities in my application.Because of that settings if I move one activity to another the first activity is destroyed.I can save my data on the onSaveInstanceState. With out using saved instance state is there any way to do...
Thanks in advance..
now is deprecated so you should use
to check if this option is enabled
update(thanks Aviv Ben Shabat comment):
to handle all sdk versions I've created a method:
I agree with @Kaediil that android applications must work well while "Don't keep activities" option is checked.
Bu for some reason if you have to check "alwaysFinishActivities" value you can use code below;
If alwaysFinishActivities option is checked and you want it to be unchecked;
You can direct user to "Settings -> Developer options" to uncheck that value. (This is better than to get extra scary permissions and set this value programatically)
int value = Settings.System.getInt(getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0);
import the following package
Then you can check if the option is enable using this code:
and you can change it using this:
Hope it helps
You could also use an intent and kill the activity each time. Just call ReturnToMain in your onBackPressed(), and it should defeat the "Don't keep activities" problem. This has been one of the problems I have been facing overseas with foreign handsets.
The other option would be @aegean's solution below. You will have to direct the user to "Settings -> Developer options" to uncheck that value. Here is what I used with a dialog box.Make sure to add the finish() so that the app doesn't crash when they push the back button, or try to restart the app after pressing the home button.
That flag is there for exactly this reason. The idea is to check and make sure your app handles its activities being destroyed. You can't override it because in the real world it might happen even without that flag if the device is low on memory. You need to code things to handle this case not override it.