Android默认的LAUNCHER活动的launchMode吗? [英] Android default launchMode of LAUNCHER activity?

查看:262
本文介绍了Android默认的LAUNCHER活动的launchMode吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

manifestlauncher activitylaunchMode是否被忽略? android文档说默认的launchMode是标准",但是如果将其应用于应用程序的主要活动,这对我来说不是逻辑,因为每次启动该应用程序时,都会另外一个task在应用程序的instance中创建.

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.

推荐答案

好吧,我亲自研究了Android资源,发现了以下内容.

Well, I delved into Android sources myself and found the following thing.

启动器使用LauncherAppsService中的方法startActivityAsUser启动应用程序.目的是使用以下几行构建的:

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);


根据Android文档,标志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.

这有效且无条件地覆盖了应用中指定的(或默认行为省略了)launchMode,并且忽略了此属性.

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.

这篇关于Android默认的LAUNCHER活动的launchMode吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆