If you leave a task for a long time, the system will clear all activities other than the root activity of the task. When the user returns this task again, only the root activity is stored. This method of system behavior is because after a long time, the user may have abandoned their jobs before returning the task, and started some new tasks.
You can use some activity attributes to modify this behavior:
1. alwaysretaintaskstate
If this attribute is set to "true" in the Root Activity of a task, the default behavior as described above will not happen. Even after a long time, this task retains all the activities in its stack.
2. cleartaskonlaunch
If this attribute is set to "true" in the Root Activity of a task, the stack will be cleared to the root activity no matter when the user leaves and returns the task. In other words, it is opposite to the alwaysretaintaskstate attribute. The user always returns to the initial state of the task, even if only the task is left for a while.
3. finishontasklaunch
This attribute is a bit like the cleartaskonlaunch attribute, but it only operates on a single activity, not the entire task. It can also cause any activity to exit, including the root activity. When this attribute is set to "true", the activity only maintains the part of the current session of the task. If the user leaves and then returns this task, it will no longer exist.