androidandroid-activityback-stacklaunchmodeandroid-task

launchmode of Android Activity


Suppose I have a task in which I have A, B & C Activities respectively. And then I'm starting a new Activity D which has singleInstance as it's launchMode.

Now, I wonder what happens in the task level? Will the same task be preserved but contains only Activity D or new task is created?


Solution

  • A new task will be created with the single Activity D. From the documentation:

    Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

    So you'll get

    Task 1: A,B,C
    Task 2: D
    

    The following two sequence are correct which confirms the docs:

    1. A -> B -> C -> D -> back -> C -> back -> B -> back -> A -> back -> Home Screen (HS)
    2. A -> B -> C -> D -> HS -> calling your task from recent apps -> D -> back -> HS