How do I know if ICS includes "Do nothing"?

How to find out in the "Do not save actions" settings the option is enabled in ics via code. If it is on, how to prevent activity.

Note. I used more actions in my application. Because of these parameters, if I transfer one action to another, the first action is destroyed. I can save my data in onSaveInstanceState. Without using the stored state of the instance, is there any way to do ...

Thanks in advance.

+12
android
Jul 25 '12 at 12:40
source share
7 answers

This flag exists for this very reason. The idea is to check and make sure that your application is ruining its activities. You cannot redefine it, because in the real world this can happen even without this flag if the device remains low in memory. You need to encode things to handle this case without overriding it.

+13
Jul 25 2018-12-12T00:
source share

import the next package

import android.provider.Settings; 

Then you can check if the option is enabled with this code:

 Settings.System.getInt(getContentResolver(),Settings.System.ALWAYS_FINISH_ACTIVITIES, 0); 

and you can change it using this:

 Settings.System.putInt(getContentResolver(),Settings.System.ALWAYS_FINISH_ACTIVITIES, 0); 

Hope this helps

+19
Oct. 19
source share
  Settings.System.ALWAYS_FINISH_ACTIVITIES 

now deprecated so you should use

  Settings.Global.ALWAYS_FINISH_ACTIVITIES.equals("1") 

to check if this option is enabled

update:

to handle all sdk versions I created a method:

 public static boolean isFinishActivitiesOptionEnabled(Context context) { int result; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { result = Settings.System.getInt(context.getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0); } else { result = Settings.Global.getInt(context.getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0); } return result == 1; } 
+9
Mar 15 '13 at 9:24
source share

I agree with @Kaediil that Android apps should work well, and the β€œDo not save actions” option is checked.

Boo for some reason, if you need to check the value of "alwaysFinishActivities", you can use the 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 the alwaysFinishActivities option is checked and you want to remove it,

You can direct the user to "Settings β†’ Developer Options" to remove this value. (This is better than getting extra scary permissions and setting this value programmatically)

 /** * 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); } 
+8
Apr 12 '13 at 7:11
source share

The defendant has the right, and he has a good question that has still not been answered :-)

I tested this problem with a simple simple example. The fact is that when the option "do not perform actions" is checked, the actions will be killed. For example: The main activity causes subactivity. The main activity is killed. Pressing subactivity again will restart Mainactivity. This can be a problem when mainactivity does multiuser things like loading content.

My conclusion about this. The option "do not keep active" is an option of the developer and should not be installed under normal user conditions. Therefore, the developer should be able to detect this parameter.

+7
Aug 10 2018-12-12T00:
source share

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

+1
Sep 26 '13 at 7:01
source share

You can also use intent and kill an action every time. Just call ReturnToMain on your onBackPressed () and it should defeat the "Do not hold actions" problem. This was one of the problems that I encountered abroad with foreign phones.

 public void ReturnToMain() { Intent view_user = new Intent(PanicAddUpdate.this, PanicAddMain.class); view_user.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(view_user); finish(); } 

Another option would be @aegean's solution below. You will need to direct the user to "Settings β†’ Developer Options" to uncheck this value. Here is what I used with the dialog box. Be sure to add the finish line () so that the application does not crash when you press the back button or does not try to restart the application after pressing the home button.

 public void showDeveloperOptionsScreen(){ new AlertDialog.Builder(this) .setTitle("Developer Options Detected!") .setMessage("In order for Sender to work properly, please uncheck the \"Don't keep activities\" option.") .setNegativeButton(android.R.string.no, null) .setPositiveButton(android.R.string.yes, new OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); finish(); } }).create().show(); } 
+1
Feb 15 '14 at 0:46
source share



All Articles