android task与back stack 开发文档翻译 - 3

  次阅读 来源:互联网(转载协议) 2016-01-14 12:43 我要评论(0)

andling affinities

处理affinity

The affinity indicates which task an activity prefers to belong to.

By default, all the activities from the same application have an affinity for each other.

So, by default, all activities in the same application prefer to be in the same task.

However, you can modify the default affinity for an activity.

Activities defined in different applications can share an affinity, or activities defined in the same application can be assigned different task affinities.

affinity表明了一个activity倾向属于哪一个task

默认的,在同一个应用中所有的activity有相同的affinity

所以默认的,同一个应用中所有的activity倾向于在相同的task中。

然而,你可以修改activity的默认affinity

在不同应用中定义的activity可以共用同一个affinity,或者定义在同一个应用中的activity可以被指定不同的任务affinity

You can modify the affinity for any given activity with the taskAffinity attribute of the <activity> element.

你可以通过<activity>元素的taskAffinity属性修改任何已知的activity的affinity

The taskAffinity attribute takes a string value, which must be unique from the default package name declared in the <manifest> element, because the system uses that name to identify the default task affinity for the application.

taskAffinity属性为一个与在<manifest>元素中默认包名不同的String类型,因为系统使用那个名字为应用标识默认任务affinity

The affinity comes into play in two circumstances:

affinity两种情况下发挥作用

1.When the intent that launches an activity contains the FLAG_ACTIVITY_NEW_TASK flag.

当启动activity的intent包含FLAG_ACTIVITY_NEW_TASK标志。

A new activity is, by default, launched into the task of the activity that called startActivity().

It's pushed onto the same back stack as the caller.

However, 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.

默认的,一个新activity会启动到调用startActivity()的activity的task中。

它被推入与调用者相同的back stack中。

然而,如果传递给startActivity()的intent包含FLAG_ACTIVITY_NEW_TASK标志,系统会寻找一个不同task来储存新activity。

经常是一个新的task

但是并不一定是这样。

如果已经存在一个与新activity相同affinity的task,那么这个activity会被启动到此task中。

如果不是这样,那就会启动一个新的task。

If this flag causes an activity to begin a new task and the user presses the Home button to leave it, there must be some way for the user to navigate back to the task.

Some entities (such as the notification manager) always start activities in an external task, never as part of their own, so they always put FLAG_ACTIVITY_NEW_TASK in the intents they pass to startActivity().

If you have an activity that can be invoked by an external entity that might use this flag, take care that the user has a independent way to get back to the task that's started, such as with a launcher icon (the root activity of the task has a CATEGORY_LAUNCHER intent filter; see the Starting a task section below).

本站部分文章来源于网络以及网友投稿,本站只负责对文章进行整理、排版、编辑,是出于传递更多信息之目的,并不意味着赞同其观点或证实其内容的真实性。如果您有什么意见或建议,请联系QQ28-1688-302!

人工智能实验室
相关文章相关文章
  • teamLab创始人猪子寿之: 抛去衣食住行,我还剩下什么?

    teamLab创始人猪子寿之: 抛去衣食住行,我还剩下什么?

  • Michael I. Jordan带你解读百万奖金ATEC蚂蚁人工智能大赛

    Michael I. Jordan带你解读百万奖金ATEC蚂蚁人工智能大赛

  • 2018深圳国际人工智能展览会 2018 shenzhen International Artif

    2018深圳国际人工智能展览会 2018 shenzhen International Artif

  • Oculus公布原型机,大幅度提升可视角,能实现140°的视场水平

    Oculus公布原型机,大幅度提升可视角,能实现140°的视场水平

网友点评网友点评
阅读推荐阅读推荐

据外媒报道,STEER打造了首款完全自动驾驶停车技术,旨在使常规车辆转变为无人驾驶车辆。STEER的首款技术应用是4级自动驾驶及网络安全停车...

近日,美国软性机器抓手制造商 Soft Robotics 宣布,获得 2000 万美元的融资,本轮投资者包括 Scale Venture Partners,Calibrate Ventures...

据外媒报道,加州车管局发布了《2017自动驾驶脱离报告(California Autonomous Vehicle Disengagement Reports)》,其中谈及了脱离的具体...

用人机语音交互,来解决智能家居适老的问题;通过家庭门禁与安防套件、空气净化套件、可燃气体与有害气体监控套件等相互联动,在不同生活情...