I'll bold the answer to your question if you don't want to read the clarification.
When using launchMode="singleInstance"
, there's two things to keep in mind:
- The Activity will always be created in a new task
- All Activities launched from this Activity will be created in a separate task
As such, an Activity with launchMode of singleInstance
will always be isolated in it's own task. There won't be another Activity inside of that task.
So with your example from your question of Activities A, B, C, and D:
- Activity A launches Activity B
- Activity B is
launchMode="singleInstance"
so it's on a new task
- Activity B launches Activity C
- Activity C is launched in the same task as Activity A
- Activity C launches Activity D
- Activity D is
launchMode="singleInstance"
so it's on a new task
From what happened here, you have one a task that stores the launchMode="standard"
Activity A and Activity C. Activity B is in it's own task. Activity D is in it's own task.
Therefore, if you choose to Back out of these Activities, you'll notice that:
- Activity D is backed and Activity C appears
- Activity C is backed and Activity A appears
This happens because Activity C is on the same task as Activity A.
Also, Activity D definitely won't be in the same task as Activity B because Activity B's task is meant only for Activity B due to launchMode="singleInstance"
.
Keep in mind that there can be any number of tasks being held in the background at once. Just that if there's too many being held or if the system requires memory, it'll start destroying these background Activities across your multiple tasks.