`
su1216
  • 浏览: 671985 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
Group-logo
深入入门正则表达式(jav...
浏览量:72009
E60283d7-4822-3dfb-9de4-f2377e30189c
android手机的安全问...
浏览量:128919
社区版块
存档分类
最新评论

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

阅读更多

由于本人英文能力实在有限,不足之初敬请谅解

本博客只要没有注明“转”,那么均为原创,转贴请注明链接

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

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

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

 

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).

如果这个标志导致一个activity开启一个新的task并且用户按home键离开它,这里必须给用户提供一些方式可以导航回这个task。

一些实体(例如notification manager)总是在外部task打开activity,从来不作为他们自己的一部分,所以他们总是在intent中加入FLAG_ACTIVITY_NEW_TASK传递给startActivity()

如果你有一个可以被可能含有此标识的外部实体调用的activity,注意用户有一种不受约束的方式来返回到开始的task ,例如通过launcher图标(task的根activity有一个CATEGORY_LAUNCHER的intent过滤器;参见下面的开启一个 task章节)

 

 

2.When an activity has its allowTaskReparenting attribute set to "true".

当一个activity的allowTaskReparenting属性设置为true

 

 

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.

这种情况下,当那个task来到前台时,activity可以从它开始的task中移动到一个有为它的affinity的task中。

 

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.

Tip: If an .apk file contains more than one "application" from the user's point of view, you probably want to use the taskAffinity attribute to assign different affinities to the activities associated with each "application".

例如:假设一个选择城市后报告天气情况的activity被定义为一个旅游应用的一部分。

它与同应用中的其他activity拥有相同的affinity(应用默认的affinity),并且allowTaskReparenting=true。

当你的一个activity开启天气预报activity时,最初它与你的activity属于同一个task。

但是,当这个旅游应用的task来到前台时,这个天气预报activity被重新分配到此task中并且在其内部显示。

提示:如果一个apk文件对于用户来说包含多个“应用”,你也许想要使用taskAffinity属性来分配不同的affinity到与activity关联的每个“应用”中。

 

 

Clearing the back stack

清除back stack

 

If the user leaves a task for a long time, the system clears the task of all activities except the root activity. 

When the user returns to the task again, only the root activity is restored. 

The system behaves this way, because, after an extended amount of time, users likely have abandoned what they were doing before and are returning to the task to begin something new.

如果用户离开task很长时间,系统清理除了task中的根activity的其他所有activity

当用户再次返回到task中,只有根activity被恢复。

系统之所以有这种行为是因为经过较长时间后,用户很可能要放弃他们之前所做的,返回到task开始做些新的事情。

 

There are some activity attributes that you can use to modify this behavior:

一些activity属性可以修改这种行为:

 

alwaysRetainTaskState

If this attribute is set to "true" in the root activity of a task, the default behavior just described does not happen. 

The task retains all activities in its stack even after a long period.

如果task的根activity的这个属性被设置为true,之前描述的默认行为就不会发生

即使在很长一段时间后,task也会保持在其stack内的所有activity

 

 

clearTaskOnLaunch

If this attribute is set to "true" in the root activity of a task, the stack is cleared down to the root activity whenever the user leaves the task and returns to it. 

In other words, it's the opposite of alwaysRetainTaskState. 

The user always returns to the task in its initial state, even after a leaving the task for only a moment.

如果task的根activity的这个属性被设置为true,每当用户离开task再返回到它,stack都会被清除只留下根activity。

换句话说,它与alwaysRetainTaskState相反。

用户总是返回到task的初始状态,即使是只离开task一小会。

 

 

finishOnTaskLaunch

This attribute is like clearTaskOnLaunch, but it operates on a single activity, not an entire task. 

It can also cause any activity to go away, including the root activity. 

When it's set to "true", the activity remains part of the task only for the current session. 

If the user leaves and then returns to the task, it is no longer present.

这个属性和clearTaskOnLaunch相似,但是它操作单一的activity而不是整个task。

它也会导致activity离开,包括根activity。

当finishOnTaskLaunch设置为true时,activity只为当前会话保持部分task。

如果用户离开又返回到这个task,这个activity将不复存在。

 

 

Starting a task

开始一个task

 

You can set up an activity as the entry point for a task by giving it an intent filter with "android.intent.action.MAIN" as the specified action and "android.intent.category.LAUNCHER" as the specified category. For example:

你可以通过指定一个action为android.intent.action.MAIN,category为android.intent.category.LAUNCHER的intent过滤器,设置一个activity作为task入口。

 

 

An intent filter of this kind causes an icon and label for the activity to be displayed in the application launcher, giving users a way to launch the activity and to return to the task that it creates any time after it has been launched.

一个这种intent过滤器导致activity的一个图标和标签显示在launcher应用中,给用户一种方式来启动activity和任何时候返回到activity被启动之后它建立的task。

 

 

This second ability is important: Users must be able to leave a task and then come back to it later using this activity launcher. 

For this reason, the two launch modes that mark activities as always initiating a task, "singleTask" and ""singleInstance", should be used only when the activity has an ACTION_MAIN and a CATEGORY_LAUNCHER filter. 

Imagine, for example, what could happen if the filter is missing: An intent launches a "singleTask" activity, initiating a new task, and the user spends some time working in that task. 

The user then presses the Home button. 

The task is now sent to the background and is not visible. 

Now the user has no way to return to the task, because it is not represented in the application launcher.

第二点很重要:用户必须有能力使用这个activity起动器离开task之后再返回到这个task。

由于这个原因,singleTask和singleInstance两种启动模式把activity标记成总是开始一个task,应该只被应用于当activity有ACTION_MAIN和CATEGORY_LAUNCHER过滤器时。

想一下,例如,如果没有过滤器将会发生什么:一个intent启动一个启动模式为singleTask的activity,初始化一个新的task,用户花费一些时间在这个task上面

然后用户按home键。

现在这个task被送到后台不再可见。

现在用户没有办法返回到这个task上了,因为它没有在launcher应用中表现。

 

For those cases where you don't want the user to be able to return to an activity, set the <activity> element's finishOnTaskLaunch to "true" (see Clearing the stack).

由于这些原因  你不希望用户返回到activity的地方,设置<activity>元素的finishOnTaskLaunch属性为true(见清除back stack)。

 

 

本文来自对下面地址的翻译,英文水平实在有限,希望拍砖同时能给予指正。

http://developer.android.com/guide/components/tasks-and-back-stack.html

 

 

 

转贴请保留以下链接

本人blog地址

http://su1216.iteye.com/

http://blog.csdn.net/su1216/

分享到:
评论

相关推荐

    Z-Stack 3.0.2-.7z.zip_Z-STACK 3.0.2_Z-STACK-3.0.2_z-stack 3_z-st

    通过下载并解压“Z-Stack 3.0.2-.7z”文件,开发者可以获得完整的SDK包,其中包括源代码、库文件、编译工具、示例应用和详细的开发文档,从而开始基于Z-Stack 3.0.2的物联网项目开发。务必仔细阅读文档,理解新特性...

    redis-stack-server 7.2.0 安装包合集

    redis-stack-server-7.2.0-v9.arm64.snap redis-stack-server-7.2.0-v9.bionic.arm64.tar.gz redis-stack-server-7.2.0-v9.bionic.x86_64.tar.gz redis-stack-server-7.2.0-v9.bullseye.x86_64.tar.gz redis-stack-...

    Android task和back stack

    即使那个activitie可能来自不同的应用,Android也靠着把两个activity保存在同一个任务中来实现这种无缝的用户体验. 一个任务是用户在执行某种工作时所交互的activitie的集合.activitie们放置在一个栈("后退栈")中,...

    android ndk-stack使用说明。

    通过以上步骤,我们可以有效地利用`ndk-stack`工具来解决在Cocos2d-x、JNI以及Android NDK开发过程中遇到的调试难题。尤其是在处理C/C++代码时,能够更加直观地看到函数调用的流程,这对于定位bug具有极大的帮助。...

    Task&BackStack;.mmap

    Task&BackStack;.mmap

    redis-stack-server-6.2.6-v7.rhel7.x86-64.tar.gz

    这里的 "redis-stack-server-6.2.6-v7.rhel7.x86-64.tar.gz" 文件是一个针对 Red Hat Enterprise Linux 7 (RHEL7) 平台的 64 位版本的 Redis Stack 6.2.6 包。这个压缩包包含了运行 Redis Stack 所需的所有组件,...

    Z-stack开发指南-中文翻译-未纠错

    **Z-stack开发指南-中文翻译-未纠错** Z-stack是由美国德州仪器(TI)提供的一种专为ZigBee无线网络设计的协议栈。ZigBee是一种基于IEEE 802.15.4标准的低功耗、低数据速率、近距离无线通信技术,广泛应用于智能...

    imsdroid android-ngn-stack

    **imsdroid与Android Ngn-stack详解** imsdroid是一个专为Android平台设计的开源项目,它致力于实现IP多媒体子系统(IMS)的功能。IMS是一种基于IP网络的通信架构,主要用于提供传统移动通信网络中的语音、视频通话...

    ndk-stack调试 cocos2d-x

    ndk-stack 是一个强大的命令行调试工具,用于调试 Native 代码,especially for Android 平台的.so 库文件。下面我们来详细了解 ndk-stack 在 cocos2d-x 中的应用。 什么是 ndk-stack? ndk-stack 是 Android NDK ...

    Android-SimpleStack这是一个简单的backstack实现

    在Android应用开发中,Backstack(返回栈)是管理Activity或Fragment导航的关键元素。它允许用户通过按下设备上的后退按钮(或者程序逻辑中触发)来按照历史顺序回溯到先前的界面。Android-SimpleStack项目提供了一...

    MTK-stack-and-stack-management-.rar_Stack_history

    3. **Task和Back Stack**:在Android中,Task是执行一系列相关Activity的容器,而Back Stack则是Task内Activity的管理结构,它维护了Activity的历史记录,使得用户可以通过返回键按顺序回到先前的Activity。...

    android-ngn-stack英文文档

    - **定义与功能**:Android-NGN-Stack 是一个为 Android 2.x 或更高版本设备设计的下一代网络(NGN)堆栈。该堆栈基于 Doubango 框架,后者是世界上最先进的开源 3GPP IMS/RCS 框架之一,适用于嵌入式系统和桌面系统...

    TI BLE-STACK-CC2540-CC2541

    TI BLE-STACK-CC2540-CC2541是Texas Instruments(TI)公司推出的针对其蓝牙低功耗(Bluetooth Low Energy, BLE)芯片CC2540和CC2541的官方开发库。这个库包含了必要的软件工具和资源,用于开发基于这些芯片的BLE...

    Z-Stack-Mesh-1.0.0,是TI(德州仪器)发布的基于CC2530的ZigBee协议栈

    该压缩包中的"Z-Stack-Mesh-1.0.0 (1).exe"文件很可能是Z-Stack-Mesh-1.0.0的安装程序,用于在开发环境中设置和配置ZigBee协议栈。通常,这个安装包会包含以下组件: 1. **开发工具**:如IAR Embedded Workbench或...

    fullstack-react-book-r36

    《fullstack-react-book-r36》是一本全面且深入的指南,专注于React及其相关的技术生态。这本书旨在帮助读者成为ReactJS领域的专家,提供最新的、详尽的教程和实践指导。以下将详细介绍React及其朋友们的核心概念和...

    PyPI 官网下载 | stackmanager-1.2.3-py3-none-any.whl

    PyPI官网下载的资源“stackmanager-1.2.3-py3-none-any.whl”就是一个这样的软件包,用于安装和管理Python项目中的依赖。 首先,我们来详细了解一下`.whl`文件。这是一种预编译的Python二进制包格式,全称为“Wheel...

    android-ngn-stack源码

    通过深入阅读和分析这些源码,开发者可以了解Android NGN Stack如何在移动设备上实现高效、可靠的通信服务,并且可以根据自己的需求进行二次开发和创新。无论是对移动通信有兴趣的初学者,还是有经验的开发者,都能...

    BLE-STACK-CC2540-CC2541

    标题“BLE-STACK-CC2540-CC2541”暗示了这是一个与蓝牙低功耗(BLE,Bluetooth Low Energy)技术相关的软件栈,主要用于Texas Instruments(TI)的CC2540和CC2541微控制器。这两个芯片是TI推出的蓝牙智能系统级芯片...

    fullstack-react-book-r39.7z

    3. **fullstack-react-code**:这个文件夹很可能包含了与书中示例代码相对应的源代码。这些代码示例可以帮助读者实际操作,加深对React工作原理的理解。通过跟随代码练习,开发者可以亲手构建React应用,提升编程...

    Android代码-Fragment-Back-Stack

    Fragment-Back-Stack Fragment Back Stack manager while displaying fragments on single activity and need to maintain on back press Purpose We know that there is activity stack in Android. We don't need ...

Global site tag (gtag.js) - Google Analytics