0

我试图了解 Android 中对任务关联性的需求。我也搜索了其他 SO 答案。

我对单任务启动模式和任务亲和性的组合特别感兴趣。

对于 singleTask 启动模式(或带有 NEW_TASK 标志的 Intent),系统会采取 3 个操作之一:

  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.

我对这个功能的问题是相似的。我无法判断此功能是满足一些必要的用户体验要求还是只是任务的一个花哨的附加组件?为什么需要跨任务重新设置活动?

有人可以帮我回答以上两个问题吗?

4

1 回答 1

1

我会在这方面刺一下!

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

所以当我读到亲和力时,我想到的是 URL、电子邮件、文档等。询问用户要打开什么应用程序是否有意义,特别是如果他们已经打开了可以处理意图的应用程序之一。

重新育儿也是如此。该任务打开另一个应用程序,但是当用户完成该任务并想要返回到原始应用程序时会发生什么?从用户的角度来看,这是一种体验,无论需要多少应用程序来满足这种体验。

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

于 2015-08-20T21:11:06.470 回答