I'm getting really confused about the different activity launchModes in Android. I understand it has something to do with the activity stack which is also something not so clear to me. I would appreciate a short explanation about each launchMode with a simple use case.
-
i think the following is a good point to start: http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode – Manu Zi Feb 24 '14 at 06:48
2 Answers
SingleTask and SingleInstance activities can only begin a task. They are always at the
root of the activity stack. Moreover, the device can hold only one instance of the
activity at a time — only one such task.
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Standard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SingleTop"
android:launchMode="singleTop" />
<activity
android:name=".SingleTask"
android:launchMode="singleTask"
android:taskAffinity="" />
<activity
android:name=".SingleInstance"
android:launchMode="singleInstance" /> <!--//TODO launchMode -->
</application>
<uses-permission android:name="android.permission.GET_TASKS" />

- 10,807
- 1
- 75
- 53
Android 4 types of launch mode:-
1.Standard
2.Single Top
3.Single Task
4.Single Instance
Standard -> When go to Activity A to activity B then new object create every time and when go back press go back multiple times.
Single Top -> when user to Activity A to activity B and again go Activity B then new instance not create and onCreate Method not call. but onNewIntent method
call.Single Task -> when user to Activity A to activity B and acitivity B to activity C again go Activity B then new instance not create and onCreate Method not call. but onNewIntent method call. and when backpress on activity B then go to activity A. Activity C is remove from mid.
Single Instance -> Activity Stack B is A to B to C. After launching the B activity, A -> B -> C -> D — Job #1 B — Job #2 (Here, B will be assigned to a separate duty)
If you continue like this and add E and B, the stack will look like this: Job #1— A -> C -> D -> E. 5. List item

- 3
- 1

- 19
- 5