does the launchMode
of the launcher activity
in the manifest
get ignored?
The android
documentation says that the default launchMode
is "standard" but this isn't logic for me if this would be applied to the main activity of an app because each time you start the app, another task
would be created in the instance
of the app.
There are four types of launch modes in Android: Standard. SingleTop. SingleTask.
standard This is the default launch mode of an activity (If not specified). 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.
As shown in the table below, the modes fall into two main groups, with " standard " and " singleTop " activities on one side, and " singleTask ", " singleInstance ", and " singleInstancePerTask " activities on the other. An activity with the " standard " or " singleTop " launch mode can be instantiated multiple times.
activity is the subelement of application and represents an activity that must be defined in the AndroidManifest. xml file. It has many attributes such as label, name, theme, launchMode etc. android:label represents a label i.e. displayed on the screen. android:name represents a name for the activity class.
Well, I delved into Android sources myself and found the following thing.
The launcher starts apps using the method startActivityAsUser
in LauncherAppsService
. The intent is constructed using these lines:
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
launchIntent.setComponent(component);
launchIntent.setSourceBounds(sourceBounds);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
According to Android documentation, the flag FLAG_ACTIVITY_NEW_TASK
means:
When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in.
This effectively and unconditionally overrides launchMode
specified (or omitted to default behaviour) in the app, and ignores this attribute.
I think this demonstrates that the documentation is not clear (or complete) enough. Without such deep investigations of the core source codes everyone can get unexpected results now and then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With