Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test android:alwaysRetainTaskState

Tags:

android

I have an application that works fine, except when it is in the background for a long time and is brought back to the foreground. I am wondering if this has anything to do with the flag alwaysRetainTaskState, when the system has cleared my activity stack. I would like to test it, but I don't want to sit around for 30 minutes every time. Is there any way to trigger the normal system behavior some other way?

Update: If I set the flag android:clearTaskOnLaunch, is it going to do the same thing as alwaysRetainTaskState when I relaunch the app?

like image 215
ADB Avatar asked Nov 06 '22 04:11

ADB


1 Answers

Is there any way to trigger the normal system behavior some other way?

The easiest way to test alwaysRetainTaskState is to leave the Activity and start up several applications (one after the other) that use a ton of memory. Its repetitive but fairly reliable. I can trigger one on my Galaxy S-II after about 40 sec if I pick the right applications.

Short of that, I know of no other direct way to test this flag.

If I set the flag android:clearTaskOnLaunch, is it going to do the same thing as alwaysRetainTaskState when I relaunch the app?

Absolutely not. ClearTaskOnLaunch basically means that your app will go back to the root activity. All other Activities are removed from your Activity Stack. This means that if your Activity relies on child Activities to deliver its content, it will all be lost. In other words, it gets the user back to the initial state of the Activity Stack for your Application. It may keep the state of that Activity depending on the alwaysRetainTaskState flag.

Additional Information

alwaysRetainTaskState is only useful on your root Activity. Its basic purpose is to keep it and all other Activities alive for a longer period of time. Any objects not directly tied to those Activities are in flux and able to be discarded. Often, if alwaysRetainTaskState is not working, it is because your code is manually getting rid of references (normally in response to onPause() or similar event).

like image 112
Fuzzical Logic Avatar answered Nov 15 '22 11:11

Fuzzical Logic