6

Launch modes in Android?

Standard: It creates a new instance of an activity in the task from which it was started. Multiple instances of the activity can be created and multiple instances can be added to the same or different tasks.
Eg: Suppose there is an activity stack of A -> B -> C.
Now if we launch B again with the launch mode is “standard”, the new stack will be A -> B -> C -> B.
singleton: It is the same as the standard, except if there is a previous instance of the activity that exists in the top of the stack, then it will not create a new instance but rather send the intent to the existing instance of the activity.
Eg: Suppose there is an activity stack of A -> B.
Now if we launch C with the launch mode as “singleton”, the new stack will be A -> B -> C as usual.
Now if there is an activity stack of A -> B -> C.
If we launch C again with the launch mode as “singleton”, the new stack will still be A -> B -> C.
SingleTask: A new task will always be created and a new instance will be pushed to the task as the root one. So if the activity is already in the task, the intent will be redirected to onNewIntent() else a new instance will be created. At a time only one instance of activity will exist.
Eg: Suppose there is an activity stack of A -> B -> C -> D.
Now if we launch D with the launch mode as “single-task”, the new stack will be A -> B -> C -> D as usual.
Now if there is an activity stack of A -> B -> C -> D.
If we launch activity B again with the launch mode as “single-task”, the new activity stack will be A -> B. Activities C and D will be destroyed.
SingleInstance: Same as a single task but the system does not launch any activities in the same task as this activity. If new activities are launched, they are done so in a separate task.
Eg: Suppose there is an activity stack of A -> B -> C -> D. If we launch activity B again with the launch mode as “single instance”, the new activity stack will be:
Task1 — A -> B -> C
Task2 — D

Comments
  • 2
    The android launch modes is too complex (in my opinion) is because they wanted to save resource (particularly RAM) in order to run on low end device.

    I know the activity stack seem too complex to follow but the work around is to use only 1 activity in our application.

    By using fragments you only need to use 1 activity.
Add Comment