How to detect if “Don’t keep activities” is Enabled

찰스의 안드로이드
Nov 6 · 1 min read

Most of Users are not devloper. For any reason, their devices are enabled for “Don’t keep activities”option in developer option.

if device is enabled, the activity manager will aggressively finish activities and
processes as soon as they are no longer needed. accordingly, some functions may not work.

The following code snippet shows how you can detect your app’s the option enabled

public boolean isAlwaysFinishActivitiesEnabled(){
int state;

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1){
state = Settings.System.getInt(
getContentResolver(),
Settings.System.ALWAYS_FINISH_ACTIVITIES,
0
);
}else{
state = Settings.Global.getInt(
getContentResolver(),
Settings.Global.ALWAYS_FINISH_ACTIVITIES,
0
);
}
return state != 0;
}
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade