Single instance launch

      Technique summary
    Technique Single instance launch
    Against Task hijacking
    Limitations Only one activity can be a part of the task
    Side effects Interaction model can be confusing for the users
    Recommendations Not recommended for use by Google in most cases

    Single instance activities permit no other activities to be a part of its task. If any exported activity in the application is launched in a single instance mode, it is impossible for a task hijacking technique to insert a malicious activity on top.

    However, protection comes at the expense of usability. In particular, the order of activities appearing on screen can be confusing for the user.

    UX impact of the single instance mode

    Activities in Android applications are organized in Tasks. Every Task has one or more Activities inside. The Activities form a stack that determines the order in which Activities are going to be displayed when the user presses the Back button.

    For example, in Task 1, the topmost Activity is B, and when the user presses the Back button, Activity A is shown.

    By default, all Activities in an application belong to the same Task, however this can be changed if an activity is launched in a different way. For example, an Activity can be forced to launch in its own separate Task by setting the Activity’s launchMode to singleInstance. If Activity B launches Activity C that is set to launch as a single instance, a new Task 2 will be created for the Activity C.

    Due to the launch mode restrictions, no other Activity can go to the Task 2. For example, if Activity C launches another Activity D, that last activity would go onto the Task 1’s stack.

    Since A launched B, and B launched C, and C launched D, the logical order in which the Activities would “unwind” when the user presses the Back button would be reversed - so first D, then C, then B, and then A.

    However, according to the stack of Task 1, when the user presses the Back button, the order would be D, B, A, and only then C. Furthermore, if a user presses the Recents button, they would see two Tasks (“applications”) for the protected application.

    If many Activities in the application are using this launch mode, the order might be confusing for the user.

    This UX impact is the reason why the use of this technique may not be recommended for all cases.

    Guardsquare

    Table of contents