Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect Developer Setting 'do not keep activities'

Tags:

java

android

How can I detect if a device has 'do not keep activities' set in developer options. I can't find this value in the settings-class.

I need this setting to know, because when 'do not keep activities' is activated my app gets problem with it. Example : I have a main-activity and a sub-activity. when I switch from main to sub and back from sub to main, then the main-activity will be started again. This is because the mainactivity was killed before. besause I do a lot of loading in my main-activity, the app is not usable when starting over and over.

Or is there any method to solve this problem ? Without this setting activated, there is no problem.

regards

like image 973
mcfly soft Avatar asked Nov 22 '25 16:11

mcfly soft


1 Answers

Is it possible to detect that flag by code ?

Yes.

In API Doc, it is called Settings.System.ALWAYS_FINISH_ACTIVITIES:

If 1, the activity manager will aggressively finish activities and processes as soon as they are no longer needed. If 0, the normal extended lifetime is used.

Constant Value: "always_finish_activities"

To get the value in code:

int value = Settings.System.getInt(getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0);

Check out the source code to see how Settings.apk did this.

like image 62
yorkw Avatar answered Nov 25 '25 05:11

yorkw