问题描述
我有两个应用程序,即应用程序A和应用程序B,现在我想从应用程序A启动应用程序B中的活动,该活动的启动模式为单任务".
I have two application, App A and App B, now I want to start an activity in App B from App A, the launchmode of this Activity is "singleTask".
订单:活动X(App A)———>活动Y(应用B)———>活动Z(应用程序B,launchMode ="singleTask")
The order:Activity X (App A) ———> Activity Y (App B) ———> Activity Z (App B, launchMode="singleTask")
作为默认的AndroidManifest配置,任务管理器中将显示两个App,我希望用户只能在任务管理器中看到App A标签,因此当他们在任务之间切换时,不要单击AppB.Android11之前Android R),我使用下面的属性taskAffinity解决了这个问题.
As default AndroidManifest config, there will be two App shown in the Task Manager, I hope users can only see App A label in Task Manager, so when they switch between tasks they don’t click App B. Before Android 11(Android R), I use the attribute taskAffinity as below to solve this problem.
活动X和活动Z都将其添加到AndroidManifet.xml
Both Activity X and Activity Z, add this in AndroidManifet.xml
android:taskAffinity =" com.abc.xxx"
因此,这些活动都可以包含在一项活动任务中.在Android 10中有效.
So these activity can both house in one activity task. In Android 10, it works.
但是,它不再适用于Android11.而且,我没有找到与此场景相关的任何新功能.
However, it doen’t work in Android11 anymore. And, I didn’t find any new features relevant to this scene.
如何使ApplicationA的活动任务容纳启动模式为singleTask的ApplicationB的活动?让用户在任务管理器中只能看到一个任务(ApplicationA).
How can I make ApplicationA’s activity task house the activity of ApplicationB which launchmode is singleTask? Let users see only one task(ApplicationA) in task manager.
推荐答案
您不能.而且你不应该.它之前工作的原因是 taskAffinity
胜过(覆盖)了 launchMode
.显然,他们已经更改/修复了Android 11中的问题.
You can't. And you shouldn't. The reason it was working before is that taskAffinity
was trumping (overriding) the launchMode
. Obviously they have changed/fixed that in Android 11.
如果将 Activity
声明为 singleTask
,则这将告知Android该 Activity
要成为根 Activity
在自己的任务中.启动此 Activity
时,应在一个新任务中启动它,而不是与 Activity
进行启动的任务相同.
If an Activity
is declared as singleTask
then this tells Android that the Activity
wants to be the root Activity
in its own task. When you launch this Activity
, it should be launched in a new task, not into the same task as the Activity
doing the launching.
在早期版本的Android中,如果 Activity
与根 Activity .从来没有清楚地记录过该文件,因此也不清楚这是否是一个"bug".或功能".看来他们终于在Android 11中对此进行了更改/修复.
In earlier versions of Android, the Activity
would be launched into the same task if the Activity
had the sametaskAffinity
as the root Activity
of the launching task. This was never clearly documented, and so it wasn't clear if this was a "bug" or a "feature". It looks like they have finally changed/fixed this in Android 11.
请参阅我对以下相关问题的回答:
See my answers to these related questions:
- https://stackoverflow.com/a/14991392/769265
- https://stackoverflow.com/a/36127362/769265
- https://stackoverflow.com/a/18622131/769265
这篇关于在Android 11中无法通过taskAffinity使用Corss应用程序活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!