Reputation: 137
Suppose there are two activities in a single android application with launch modes as 'singleInstance'. Assume an example below.
I am navigating from activity A -> B(launchMode="singleInstance"
). Now from activity B -> C. Finally, I navigate from activity C -> D(launchMode="singleInstance"
).
Now we know instance of activity B will be created in a different task, and A & C will be in the different task.
Now, my question is, in which task instance of activity D would be placed. Will it be with activity B, or some other task would be created for activity D.
Thanks.
Upvotes: 4
Views: 1058
Reputation: 3234
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:
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:
launchMode="singleInstance"
so it's on a new tasklaunchMode="singleInstance"
so it's on a new taskFrom 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:
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.
Upvotes: 5