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

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

Managing Tasks

管理task

The way Android manages tasks and the back stack, as described above—by placing all activities started in succession in the same task and in a "last in, first out" stack—works great for most applications and you shouldn't have to worry about how your activities are associated with tasks or how they exist in the back stack.

However, you might decide that you want to interrupt the normal behavior.

Perhaps you want an activity in your application to begin a new task when it is started (instead of being placed within the current task); or, when you start an activity, you want to bring forward an existing instance of it (instead of creating a new instance on top of the back stack); or, you want your back stack to be cleared of all activities except for the root activity when the user leaves the task.

android管理task和back stack的方式,像上面描述的那样-通过在相同的task中连续的放置打开的activity并且用一个“后进先出”的stack,为大多数应用很好的工作,你没必要担心如何将你的activity与task关联或者他们如何存在于back stack中。

也许你想要你应用中的一个activity被打开时开始一个新的task(代替放在当前的task中);或者当你打开一个activity时,你想把之前已经存在的此activity实例带到前台(代替在back stack顶部新建一个实例);或者当用户离开这个task时,除了根activity,你想要清空stack中的所有activity。

You can do these things and more, with attributes in the <activity> manifest element and with flags in the intent that you pass to startActivity().

使用在<activity>中的清单元素的属性和传递给startActivity()函数的intent中的标志,你可以做到上面那些并且可以做的更多

In this regard, the the principal <activity> attributes you can use are:

在这方面,你可以使用的主要的<activity>属性有:

taskAffinity

launchMode

allowTaskReparenting

clearTaskOnLaunch

alwaysRetainTaskState

finishOnTaskLaunch

And the principal intent flags you can use are:

你可以使用的主要的intent标志有:

FLAG_ACTIVITY_NEW_TASK

FLAG_ACTIVITY_CLEAR_TOP

FLAG_ACTIVITY_SINGLE_TOP

In the following sections, you'll see how you can use these manifest attributes and intent flags to define how activities are associated with tasks and how the behave in the back stack.

下面的章节中,你会看到如何使用这些清单属性和intent标志来定义如何把activity与task关联和back stack如何表现。

Defining launch modes

定义启动模式

Launch modes allow you to define how a new instance of an activity is associated with the current task. You can define different launch modes in two ways:

启动模式允许你定义如何实例化一个与当前task关联的activity

你可以通过两种方式定义不同的启动模式

Using the manifest file

1使用manifest文件

When you declare an activity in your manifest file, you can specify how the activity should associate with tasks when it starts.

当你在你的manifest文件中定义一个activity时,你可以指定当这个activity打开时,它应该如何与task关联。

Using Intent flags

2使用intent标志

When you call startActivity(), you can include a flag in the Intent that declares how (or whether) the new activity should associate with the current task.

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

人工智能实验室
相关文章相关文章
  • Oculus公布原型机,大幅度提升可视角,能实现140°的视场水平

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

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

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

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

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

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

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

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

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

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

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

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