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;
/**
* returns true if AlwaysFinishActivities option is enabled/checked
*/
private boolean isAlwaysFinishActivitiesOptionEnabled() {
int alwaysFinishActivitiesInt = 0;
if (Build.VERSION.SDK_INT >= 17) {
alwaysFinishActivitiesInt = Settings.System.getInt(getApplicationContext().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0);
} else {
alwaysFinishActivitiesInt = Settings.System.getInt(getApplicationContext().getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0);
}
if (alwaysFinishActivitiesInt == 1) {
return true;
} else {
return false;
}
}
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)
/**
* shows Settings -> Developer options screen
*/
private void showDeveloperOptionsScreen(){
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}