InterviewSolution
| 1. |
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 the instance of activity B will be created in a different task, and A & C will be in different tasks.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? |
|
Answer» Launch mode is an instruction for ANDROID OS which specifies how the activity should be launched. It instructs how any new activity should be associated with the current task. So in your scenario When using launchMode="singleInstance", there are two THINGS that we need to remember:
As such, an Activity with launchMode of singleInstance will always be isolated in its 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:
From what happened here, you have one a task that stores the launchMode="standard" Activity A and Activity C. Activity B is in its own task. Activity D is in its own task. Therefore, if you choose to Back out of these Activities, you'll notice that:
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". |
|