after looking up the 'Defining launch modes' section of the 'Tasks and Back Stack' guide , I dont understand exactly the behavior of an activity declared with "singleTask".
assume that I start a singleTask-activity (via startActivity method ) when there is an instance of that activity laying at the bottom(root activity) of a background task,
as the article describes, the Intent I use to start singleTask-activity will be delivered to the instance, in this case, does the instance bring itself to top of its task and its task to foreground, or just bring its task to foreground without bringing itself to top of its task?
Do I make myself clear? pls help! thanks in advance
I was/am having the same question actually. After reading replies here on stackoverflow and doing some experiments, I believe that when a singleTask activity is launched while it's already in a background task, the system will kill all other activities at the top of the stack and resume the singleTask activity.
For sure, this is not what I got out of the documentation though.
Here is my theory:
Launch Modes: Activity A: singleTask , Activity B: standard
experiment 1
experiment 2
In my case, I had to use android:alwaysRetainTaskState="true"
although this is not ideal as I do want the stack to be cleared after, say, 10 minutes as this recommendation makes sense:
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.
from the Tasks and Back Stack guide.
I hope this helps other people.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With