Launch modes in Android
Launch mode can be defined in two ways:
- Using Manifest file
- Using Intent flags
Types of Launch modes
- standard(Default)
- singleTop
- singleTask
- singleInstance
- standard :- One Activity can be instantiated multiple times and added to backstack(default nature of activities).
example : A →B →C →A →C →A →A →A (All added to backstack)
2. singleTop :- If A activity is at the top and we try to instantiate it again then onNewIntent() method will get call without creating a new instantiate.
example → A →B →C →A(new Instance) →A(no new instance only onNewIntent() method will get call of previous instance, and will not add in backstack)
3. singleTask :- single task means only one task will be available at a time.
example :- A →B →C →B (where B is singleTask)
result :- A →B (C will get destroy to maintain singleTask and onNewIntent() of Activity B will get call)
4. singleInstance :- singleInstance means only one instance of the activity will be available in another stack.
example 1 :- A →B →C →B (B is singleInstance)
result 1 : A →C →B(available in backstack)
example 2 :- A →B →C →B →C(B is singleInstance)
result 2 :- A →C →C(available in backstack, B is available in another stack)
Please do comment if you have any doubts or need improvement.