Android Lollipop 行为更改

标签 android android-5.0-lollipop launchmode

根据 Android Lollipop 的更改,引用:

StackOverflow Question

Cheese factory blog

我希望当我从我的应用程序启动其他应用程序的 Activity 时,即使行为是默认的(启动模式是标准的),它也应该在新任务中打开。因此,我制作了 2 个测试应用程序来验证相同的行为。但令人惊讶的是,如果没有指定启动模式,另一个应用程序总是在我的应用程序的任务中打开。我已经在小米红米 Note 3 (5.1.1)、Marshmallow 模拟器 (x86) 上进行了测试,两者的行为是相同的。我希望得到一些有关这方面的帮助,以及来自 Android 开发者网站的引用链接。

一些代码:

Launching app : 
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
startActivity(intent);
break;

App to be launched : 
<activity android:name="com.android.sample.launchdemo.ActivityB">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
</activity>

在启动应用程序时单击按钮,会触发 Intent 并成功打开 Activity B,但在相同的任务中。预先感谢您的任何帮助/建议。

最佳答案

看完文档后,我的感觉是标准模式的工作方式与Android 5.0(Lollipop)之前的工作方式相同。奶酪工厂博客文章是唯一指定该操作的文章,甚至根据我自己的经验,标准启动模式也已在发送的同一任务中打开了一个 Activity (除非通过 Intent 标志)。如果我错了,有人纠正我,但 Android 文档中没有指定标准模式将打开一个新任务。来自 Android 文档:

"standard" (the default mode): The system creates a new instance of the activity in the task from which it was started and routes the intent to it. The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances. See full documentation

对于您正在寻找的内容,当触发Intent时,保证新任务的唯一方法是使用标志FLAG_ACTIVITY_NEW_TASK。您可以通过调用 intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK)intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) (后者用于将标志链接在一起,因为该方法将返回 Intent )。

经过更多研究后,Android 5.0 Lollipop 中似乎做出的唯一更改(与此相关)是最近的应用程序屏幕可以显示 Activity 的多个实例。

In previous releases, the recents screen could only display only one task for each app that the user interacted with most recently. Now your app can open more tasks as needed for additional concurrent activities for documents. This feature facilitates multitasking by letting users quickly switch between individual activities and documents from the recents screen, with a consistent switching experience across all apps. Examples of such concurrent tasks might include open tabs in a web browser app, documents in a productivity app, concurrent matches in a game, or chats in a messaging app.

对我来说,这似乎是唯一相关的变化,并且帖子(cheesefactory 和 SO)设置了 documentLaunchMode 来为每个 Activity 创建新任务(考虑到 Cheesefactory 有一个,这很可能是这种情况) “图库”应用程序)。有关 concurrent documents 的文档和 documentLaunchModedocumentLaunchMode 和标志 FLAG_ACTIVITY_NEW_TASK 可以配置为执行类似的操作,documentLaunchMode 是首选。

关于Android Lollipop 行为更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37827304/

相关文章:

android - 为什么行为不同?- android :launchMode ="singleTask" , android :taskAffinity ="" And Intent. FLAG_ACTIVITY_NEW_TASK

java - LayoutInflater 异常

android - 在具有根访问权限的 Android L 上禁用/启用移动数据

android - 标记为 "SingleTask"的 Activity 已提前

android - 通知栏图标在 Android L 中变白

android - 具有共享元素的 Activity 转换中出现问题

android - 使用通知恢复单个实例 Activity

Android - 在表格行内以编程方式设置按钮宽度

android - 内存泄漏和 OutOfMemoryError

安卓媒体播放器错误-1004 (ERROR_IO)