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!

人工智能实验室
相关文章相关文章
  • 未来两年人工智能要怎么走?看这篇就够了

    未来两年人工智能要怎么走?看这篇就够了

  • 英国研发“杀生”机器人 通过生命体获取能量

    英国研发“杀生”机器人 通过生命体获取能量

  • 韩春雨称已能重复实验结果 近期将有消息公布

    韩春雨称已能重复实验结果 近期将有消息公布

  • 无人驾驶汽车如何改变城市生活?听听他们怎么说

    无人驾驶汽车如何改变城市生活?听听他们怎么说

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

据国外媒体报道,在过去两年内,聊天机器人(chatbot)、人工智能以及机器学习的研发和采用取得了巨大进展。许多初创公司正利用人工智能和...

霍金 视觉中国 图 英国著名物理学家霍金(Stephen Hawking)再次就人工智能(AI)发声,他认为:对于人类来说,强大AI的出现可能是最美妙的...

文|郑娟娟 今年,人工智能(AI) 60岁了。在AI60岁的时候,笔者想要介绍一下AI100,一个刚刚2岁的研究项目,但它的预设寿命是100年,甚至更长...

AlphaGo与李世石的人机大战,为大众迅速普及了人工智能的概念。 但对谷歌而言,除了下围棋,现在的人工智能进展到哪一步了?未来,人工智能...