taskAffinities属性用于指定Activity被启动时放到哪一个Task中
在以下两种情况下,taskAffinities会被用到:
1. 如果启动这个Activity的Intent含有 FLAG_ACTIVITY_NEW_TASK标志,且此时系统中还没有这个Activity的实例,那么系统会在新的Task中创建这个Activity,如果这个Activity指定了taskAffinities参数(假设指定了Task X),且taskAffinities指定的Task X在系统中是存在的,那么系统会在Task X中创建这个Activity的实例。
2. 当这个Activity设置了allowTaskReparenting为true时,此时,当taskAffinities指定的Task被移到前端时,这个Activity可以从开始的Task移到taskAffinities指定的Task上。
In this case, the activity can move from the task it starts to the task it has an affinity for, when that task comes to the foreground.
For example, 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.