- 浏览: 662267 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
yigeisme:
你好,不已.html和.jsp和.jpg结尾的正则表达式怎么写 ...
深入入门正则表达式(java) - 2 - 基本实例 -
su1216:
多谢指正yigeisme 写道1-12(小时,月份)正则:^( ...
深入入门正则表达式(java) - 2 - 基本实例 -
yigeisme:
1-12(小时,月份)正则:^(1[012]|\d)$应该改成 ...
深入入门正则表达式(java) - 2 - 基本实例 -
heikefangxianceshi:
小三将军 写道楼主,我想问下你给的Real.tar.gz是什么 ...
android手机root后的安全问题 (一) -
heikefangxianceshi:
这个程序运行的前提是手机root,但你的手机怎么root的呢? ...
android手机root后的安全问题 (一)
由于本人英文能力实在有限,不足之初敬请谅解
本博客只要没有注明“转”,那么均为原创,转贴请注明链接
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地址
发表评论
-
android 第三方app截图
2017-08-17 15:18 1169将View生成相应的图片 ... -
android截图事件监听
2017-07-20 18:37 2007android系统没有对用户截屏行为提供回调的api,所以我 ... -
android widget(桌面小部件)实现
2017-06-30 13:02 1989本文介绍如何自己实现一个widget以及各种注意事项。 ... -
acra简析
2016-07-31 23:54 0版本4.9.1 acra是用来在 ... -
android版本差异
2016-07-28 14:42 0这里只列出部分开发相关内容 notification ... -
android系统提供的常用命令行工具
2016-06-21 13:17 5000本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链 ... -
标示与掩码
2015-10-21 23:00 0掩码(英语:Mask) ... -
通过蓝牙调试(穿戴设备app) - 开发文档翻译
2015-09-30 11:43 2558由于本人英文能力实在 ... -
打包穿戴设备app - 开发文档翻译
2015-09-29 17:19 1784由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没 ... -
弧形进度条(动画版)
2015-07-23 17:00 5834本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链接 ... -
使用canvas与Paint在View中居中绘制文字
2015-07-15 23:03 8898本博客只要没有注明 ... -
android 关于提高第三方app的service优先级
2014-06-23 23:14 3100本博客只要没有注明“转”,那么均为原创,转贴请注明本博客链 ... -
android <application> 开发文档翻译
2014-05-24 23:47 5095由于本人英文能力实 ... -
android中各种log的抓取
2013-12-23 13:15 01.logcat的使用 2.内存快照的抓取 ... -
android多语言项目中字符串的移植(bash工具)
2013-11-11 13:31 2435有时候我们会遇到这样一种情况: 一些字符串资源要从原始项 ... -
android 高效显示Bitmap - 开发文档翻译
2013-09-13 17:59 2585由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没 ... -
android 在你的UI中显示Bitmap - 开发文档翻译
2013-09-06 19:33 6559由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没 ... -
android 管理Bitmap内存 - 开发文档翻译
2013-08-27 15:39 4100由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没 ... -
android 缓存Bitmap - 开发文档翻译
2013-08-25 13:01 3136由于本人英文能力实在有限,不足之初敬请谅解 本博客只要没有 ... -
android 在UI线程之外处理Bitmap - 开发文档翻译
2013-08-12 13:30 3361由于本人英文能力实 ...
相关推荐
即使那个activitie可能来自不同的应用,Android也靠着把两个activity保存在同一个任务中来实现这种无缝的用户体验. 一个任务是用户在执行某种工作时所交互的activitie的集合.activitie们放置在一个栈("后退栈")中,...
最近发布的Zstack 3.0.2 SDK 和说明文档
imsdroid 包含文档和android-ngn-stack,和库文件
Task&BackStack;.mmap
Ti提供的免费Z-Stack协议栈开发指南英文资料的翻译。翻译的不好,请各位指正。topeak001@163.com
Simple Stack 这是一个简单的backstack实现,它理论上基于Flow 0.9
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 ...
z-stack代码分析--osalInitTasks函数1
BLE-STACK-CC2540-CC2541
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-...
fullstack-react-book-r39 版本日期:Revision 39 - 2019-01-10 React 版本:16.7 源于网络,归于网络
阿里云 专有云企业版 V3.6.2 Apsara Stack控制台 开发指南 - 20190322.pdf
本项目这是一个纯静态的网址导航网站,项目基于bootstrap前端框架开发,基于Java开发的后台系统 框架:Guns Springboot
大名鼎鼎的TI旗下BLE芯片CC2540/CC2541的官方开发库文件,安装后自动有BTOOL。
资源来自pypi官网。 资源全名:stackmanager-1.2.3-py3-none-any.whl
Android的NGN堆栈是一个NGN(下一代网络)堆栈为Android2.X(或更高版本) 设备
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
The up-to-date, in-depth, complete guide to React and friends. Become a ReactJS expert today.
redis-stack-server-6.2.4-v1.rhel7.x86_64.tar.gz