Android default launchMode of LAUNCHER activity?

后端 未结 5 962
礼貌的吻别
礼貌的吻别 2021-02-18 23:07

does the launchMode of the launcher activity in the manifest get ignored? The android documentation says that the default

5条回答
  •  旧巷少年郎
    2021-02-18 23:57

    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.

提交回复
热议问题