Sobes.tech
Junior — Middle

Can you explain the working principle of launchMode in Android and its main options?

sobes.tech AI

Answer from AI

In Android, launchMode determines how the system manages Activity instances in the task stack when launching.

Main options:

  • standard (default): each launch creates a new Activity instance, even if one already exists in the stack.
  • singleTop: if the top element of the stack is already a running Activity of the same class, a new instance is not created, and onNewIntent() is called.
  • singleTask: only one instance of the Activity is created in the stack; if the Activity already exists, the system brings it to the top and calls onNewIntent().
  • singleInstance: similar to singleTask, but the Activity is launched in a separate task, isolated from others.

Example of usage in the manifest:

<activity android:name=".MyActivity" android:launchMode="singleTop" />

This helps control navigation behavior and prevent screen duplication.

Can you explain the working principle of launchMode… - sobes.tech