Android - 需要任务亲和力,单任务启动模式和任务重定父级



我试图理解任务亲和在Android中的需要。我也搜索了其他的答案。

我对singleTask启动模式和任务关联的结合特别感兴趣。

对于singleTask启动模式(或带有NEW_TASK标志的Intent),系统采取以下三种动作之一:

  1. 如果活动存在,它将恢复它
  2. 如果活动不存在,它将寻找具有匹配亲和力的任务来添加活动
  3. 如果没有找到匹配的任务,系统将以该活动作为根创建一个新任务

从这个答案中我有点理解第一种情况的必要性。它讨论了在多个状态下拥有相同的活动,以及它如何在用户体验中产生不一致的问题。

我更困惑的是第二种情况——为什么系统需要找到一个具有相同亲和力的现有任务?如果不允许这个特性,它会满足什么样的用例?为什么有必要?

从这个链接:

... if the intent passed to startActivity() contains the
FLAG_ACTIVITY_NEW_TASK flag, the system looks for a different task to
house the new activity. Often, it's a new task. However, it doesn't have to be. 
If there's already an existing task with the same affinity as the new activity, the 
activity is launched into that task. If not, it begins a new task.

同一链接还讨论了task reparenting。这是另一个特点我不明白。这个链接确实给出了一个天气/旅游应用的例子:

... suppose that an activity that reports weather conditions in selected cities 
is defined as part of a travel application. It has the same affinity as other 
activities in the same application (the default application affinity) and it allows 
re-parenting with this attribute. When one of your activities starts the weather 
reporter activity, it initially belongs to the same task as your activity. 
However, when the travel application's task comes to the foreground, the weather 
reporter activity is reassigned to that task and displayed within it.

我对这个特性的问题也是类似的。我不知道这个功能是为了满足一些必要的用户体验要求,还是只是一个花哨的附加任务?为什么活动需要跨任务重新父级?

谁能帮我回答一下以上两个问题?

我来试试!

我相信Android/Google的意图是为用户提供无缝的交互。

所以当我读到亲和性时,我想到的是url、电子邮件、文档等等。问用户打开哪个应用程序有意义吗?尤其是当他们已经打开了一个可以处理意图的应用程序时。

同样适用于重新养育。该任务打开了另一个应用程序,但是当用户完成该任务并希望返回到原始应用程序时会发生什么?从用户的角度来看,无论需要多少应用程序来满足这种体验,它都是一种体验。

(我发誓我在Android的Material Design文档....中读到过)

最新更新