android:taskAffinity
The task that the activity has an affinity for. Activities with the same affinity conceptually belong to the same task (to the same "application" from the user's perspective). The affinity of a task is determined by the affinity of its root activity.
The affinity determines two things — the task that the activity is re-parented to (see the allowTaskReparenting attribute) and the task that will house the activity when it is launched with the FLAG_ACTIVITY_NEW_TASK flag.


By default, all activities in an application have the same affinity. You can set this attribute to group them differently, and even place activities defined in different applications within the same task. To specify that the activity does not have an affinity for any task, set it to an empty string.
If this attribute is not set, the activity inherits the affinity set for the application (see the <application> element's taskAffinity attribute). The name of the default affinity for an application is the package name set by the <manifest> element.
activity用affinity来标识它所属的task.拥有相同affinity的activity属于同一个task。task的affinity由根activity的affinity来定义
affinity决定两件事情:
1、当activity更换从属task时(与allowTaskReparenting相关)
2、当以FLAG_ACTIVITY_NEW_TASK方式加载一个activity时,该activity由放到哪个task中。
缺省的,一个应用的所有activity拥有相同的affinity,你也可以设置这个属性来把他们划分到不同的task里面,甚至把定义在不同应用中的activity放到同一个task.如果要描叙一个activity对所有的task都没有affinity,把他设置为一个空字符串
如果这个属性没有设置,activity从application继承他的taskAffinity属性,taskAffinity的名字缺省跟包名一样的。



android:allowTaskReparenting
Whether or not the activity can move from the task that started it to the task it has an affinity for when that task is next brought to the front — "true" if it can move, and "false" if it must remain with the task where it started.
If this attribute is not set, the value set by the corresponding allowTaskReparenting attribute of the <application> element applies to the activity. The default value is "false".
Normally when an activity is started, it's associated with the task of the activity that started it and it stays there for its entire lifetime. You can use this attribute to force it to be re-parented to the task it has an affinity for when its current task is no longer displayed. Typically, it's used to cause the activities of an application to move to the main task associated with that application.
For example, if an e-mail message contains a link to a web page, clicking the link brings up an activity that can display the page. That activity is defined by the browser application, but is launched as part of the e-mail task. If it's reparented to the browser task, it will be shown when the browser next comes to the front, and will be absent when the e-mail task again comes forward.
The affinity of an activity is defined by the taskAffinity attribute. The affinity of a task is determined by reading the affinity of its root activity. Therefore, by definition, a root activity is always in a task with the same affinity. Since activities with "singleTask" or "singleInstance" launch modes can only be at the root of a task, re-parenting is limited to the "standard" and "singleTop" modes. (See also the launchMode attribute.)
用来描述当那个task下一次切换到前台的时候一个activity是否可以从启动他的task移动到另外一个拥有跟它相同affinity的task,为true表示可以移动,fase表示必须留在启动他的task中
如果activity没有设置这个属性,则它的上一级的application的allowTaskReparenting应用到该application下的所有activity,缺省值为false
一般情况下,当一个activity启动的时候,它和一个task相关,并且它的整个生命周期都呆在这个task中,你也可以使用这个标签来强制他切换到另外一个和它拥有相同affinity的task,切换的时机是当这个task不在显示时。典型的,它用于使一个application的activity移动到和这个application相关的朱task
例如,一个e-mail消息包含一个网页链接,点击这个链接将出发一个activity来显示这个页面,这个activity是有浏览器应用定义的,但是是由e-mail应用程序加载的,所以也属于e-mail这个task。如果这个显示页面的activity切换了其task从属到浏览器,那么当浏览器应用下次在前台显示的时候这个显示页面的activity将会显示,并且当e-mail这个task切换到前台是不会再显示


一个activity的affinity属性由他的taskAffinity属性定义,而一个task的affinity由它的root activtity定义。所以,一个task的root activity总是拥有和它所在task相同的affinity。由于以singleTask和singleInstance启动的ctivity只能是一个task的root activity 所以re-parenting仅限于以standard 和singleTop启动的activity.

更多相关文章

  1. Android之Animation属性配置文件
  2. RelativeLayout相关属性
  3. ImageView属性中android:src和android:background有什么区别
  4. Android Imageview 图片居左居右,自定义圆角
  5. android预定义样式简述

随机推荐

  1. AndroidAnnotations——Injecting Views
  2. 水波纹效果---3环波纹
  3. Android:Android布局方式
  4. andriod之ContentProvider读取外部存储图
  5. android 使用sharedPreferences保存用户
  6. android获取manifast.xml里面meta信息
  7. Android与Javascript交互示例(二)
  8. 百度地图实现拖动图标输入地址
  9. Android用Proguard混淆代码遇到的问题
  10. VideoView和MediaController实现网络视频