What values can the launchMode attribute take in Android?
sobes.tech AI
Answer from AI
-
standard: Creates a new instance of the activity in the task from which it is called, or in a new one if the call is from another task with theFLAG_ACTIVITY_NEW_TASKflag. Each new Intent creates a new instance of the activity. -
singleTop: If an instance of the activity already exists at the top of the stack in its task, a new instance is not created, and instead theonNewIntent()method of the existing instance is called. Otherwise, a new instance is created. -
singleTask: Creates a new task for the activity if it does not exist, and places the activity at the root of it. If an instance of the activity already exists in another task, the system brings that task to the foreground and calls theonNewIntent()method of the existing instance. All activities above the found instance in the stack are destroyed. -
singleInstance: Same assingleTask, but with one key difference: the task containing the activity can contain only this one instance of the activity. Any other activities launched from this one are started in a separate task.
<!-- Example usage in AndroidManifest.xml -->
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<!-- ... -->
</activity>