According to the Android documentation, the system will clear a task (finish all Activities above the one that launched the task) that it deems to have been abandoned by the user:
https://developer.android.com/guide/components/tasks-and-back-stack.html#Clearing
If the user leaves a task for a long time, the system clears the task of all activities except the root activity. When the user returns to the task again, only the root activity is restored. The system behaves this way, because, after an extended amount of time, users likely have abandoned what they were doing before and are returning to the task to begin something new.
https://developer.android.com/guide/topics/manifest/activity-element.html#always
Normally, the system clears a task (removes all activities from the stack above the root activity) in certain situations when the user re-selects that task from the home screen. Typically, this is done if the user hasn't visited the task for a certain amount of time, such as 30 minutes.
This behaviour can be easily reproduced on devices running Gingerbread and earlier. Launch an app and create some back history, then hit the home button and wait half an hour. Launch the app again from the home screen and the state has been cleared as if it were starting a new task. Perfect.
However, on devices running ICS and above I cannot seem to reproduce this behaviour at all, even after a task has been inactive after many hours or days. When an app is relaunched from the home screen the task is always in the state I left it in.
Assuming the documentation is correct, under what conditions will modern versions of Android (API 14+) automatically clear a task?
If the behaviour has changed and the documentation is out of date, what is the purpose of the alwaysRetainTaskState
attribute for <activity/>
? Has the default value changed to "true"
or is this attribute now deprecated?
Note: I am not talking here about Android's process lifecycle management, which will be device resource dependent. Killing a process should be transparent to the user anyway and does not affect the task state.
alwaysRetainTaskState
to"false"
? What about waiting for a longer period of time? e.g. overnight!