performance – Whats the main advantage and disadvantage of "do not keep activities" in android-ThrowExceptions

Exception or error:

One query I would like to have if anyone could answer it like: Do not keep activities options to be checked during testing android mobile application from developers options.

I used it in my application and found that my application behaves inappropriately and crashed when I switched ON Do not keep activities in android.

My questions were few :

1: How much this option will affect mobile applications?

2: What exactly does this do?

It sounds like an app killer,I notice in the Developer Options there is a box that says Do not keep activities – destroy every activity as soon as the user leaves it .

Does this create any positive and or negative functionality on my apps?

Does that mean if I open an app and as soon as I leave it, it actually closes that app and I wouldn’t see it in the task manager to manually kill it? If so, isn’t this a good thing to keep the RAM usage low?

What were the advantages and disadvantages of using it while keeping Do not keep activities ,Kindly share the experience on it.

How to solve:

How much this option will affect mobile applications?

If they are well writen this option will not affect them.

What exactly does this do?

If you have this option turned on only variables kept in activity with method onSaveInstanceState
will be saved when you go to another activity or app goes in background. All other variables will be removed immediately.
When this option is off there is possibility that these variable will be kept

Does that mean if I open an app and as soon as I leave it, it actually closes that app and I wouldn’t see it in the task manager to manually kill it?

No it means that all not kept variables will be removed. When you in example press home button.

Does this create any positive and or negative functionality on my apps?

No it only helps to develop application properly. It helps to predict unexpected situations.


Do not Keep Activities is purely a developer option that will help you to check if

  1. You have Saved the state of the activity, before it goes background.

2̶.̶ ̶H̶a̶n̶d̶l̶e̶d̶ ̶L̶o̶w̶ ̶M̶e̶m̶o̶r̶y̶ ̶S̶i̶t̶u̶a̶t̶i̶o̶n̶s̶ ̶p̶r̶o̶p̶e̶r̶l̶y̶(̶i̶n̶ ̶w̶h̶i̶c̶h̶ ̶c̶a̶s̶e̶ ̶t̶h̶e̶ ̶a̶c̶t̶i̶v̶i̶t̶y̶ ̶w̶i̶l̶l̶ ̶b̶e̶ ̶d̶e̶s̶t̶r̶o̶y̶e̶d̶)̶.̶ ̶

Edit : This option does not emulate Low memory Situations. When the device experiences low memory, the system might ask the activity to Drop by calling Finish() or it may go ahead and kill the process completely, as the comment says.

It is still good to develop with this option enabled. You will have to properly code the onSaveInstanceState() and onRestoreInstanceState() methods. By doing this, even if the process gets killed, when the user navigates back to this activity, onCreate() will be called with the savedInstanceState that was saved in the onSaveInstanceState(Bundle) method.



Developer can check the abnormal behaviour of their application and fix the cases of low memory - framework kills the application


If user has unknowingly enabled this option, then the device will work slow and every activities will be re-created across user navigation on his device. This will hinder user work

Very good answer is given in xda developer forum about usage of this option


As an addition to answers above is another, not visible from the first look disadvantage that you can test only activity destroying/recreation issues with this option, but not the whole process of application recreation due to memory lack or other system conditions, because all independent from activity memory stays.

Imagine that you have some singleton on which your classes are dependent. After system have killed app your singletons will be also cleared and restored with beginning state in case you haven’t implemented its restoring by yourself. So, despite of your activity view state & fields would be restored in case onSaveInstanceState & onRestoreInstanceState was implemented correctly, that’s not guarantee a correct app behavior after restoring, even on the particular screen. That should be considered

So to test such fully case you should stop application manually, but don’t drop it from task manager. Easiest way – with stop red square button in android studio. And open app again.

See more


“Do not keep activities” advantage is that it emulate system low memory situation when it start killing different parts of the app. Your app must maintain this situation. Disadvantage is that this option is kind of stricted and kill only activities when there is no way emulate this for services

Leave a Reply

Your email address will not be published. Required fields are marked *