Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android default launchMode of LAUNCHER activity?

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.

like image 223
David Avatar asked Sep 05 '13 12:09

David


People also ask

What is the default launch mode of an activity?

There are four types of launch modes in Android: Standard. SingleTop. SingleTask.

Which launch mode is utilized to bring a default activity to the foreground?

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.

How many android launch modes are there?

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.

What is activity tag android?

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.


1 Answers

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.

like image 121
Stan Avatar answered Oct 30 '22 09:10

Stan