由于本人英文能力实在有限,不足之初敬请谅解
本博客只要没有注明“转”,那么均为原创,转贴请注明链接
android task与back stack 开发文档翻译 - 1
android task与back stack 开发文档翻译 - 2
android task与back stack 开发文档翻译 - 3
Task和Back Stack
An application usually contains multiple activities.
Each activity should be designed around a specific kind of action the user can perform and can start other activities.
For example, an email application might have one activity to show a list of new email.
When the user selects an email, a new activity opens to view that email.
一个应用通常包含多个activity
每个activity都应该被设计成围绕着一种用户可执行并且能打开其他activity明确的action
例如:一个邮件应用也许有一个activity用来显示新邮件列表
当用户选中一封邮件时,一个新activity被打开,用来查看这封邮件。
An activity can even start activities that exist in other applications on the device.
For example, if your application wants to send an email, you can define an intent to perform a "send" action and include some data, such as an email address and a message.
An activity from another application that declares itself to handle this kind of intent then opens.
In this case, the intent is to send an email, so an email application's "compose" activity starts (if multiple activities support the same intent, then the system lets the user select which one to use).
When the email is sent, your activity resumes and it seems as if the email activity was part of your application.
Even though the activities may be from different applications, Android maintains this seamless user experience by keeping both activities in the same task.
一个activity甚至可以打开设备中存在于其他应用的activity
例如:如果你的应用想发送一封邮件,你可以定义一个intent用来执行一个发送的action并且包含一些数据,比如邮件地址和信息
其他应用中,声明它自己可以处理这样的intent的activity会打开。
这个例子中,intent用来发送邮件,所以一个邮件程序的"compose" activity会启动(如果多个activity都支持这个intent,那么系统会让用户选择使用哪一个)
当邮件发送完毕,你的activity会resume并且邮件的activity看上去好像你的应用的一部分
虽然activity可能来自不同的应用,Android通过保持两个应用的activity在同一个task中来保持这种无缝的用户体验。
A task is a collection of activities that users interact with when performing a certain job.
The activities are arranged in a stack (the "back stack"), in the order in which each activity is opened.
一个task是用户执行一个任务时,与用户交互的activity的一个集合
这些activity按着被打开的顺序被整理到一个stack中(back stack)
The device Home screen is the starting place for most tasks.
When the user touches an icon in the application launcher (or a shortcut on the Home screen), that application's task comes to the foreground.
If no task exists for the application (the application has not been used recently), then a new task is created and the "main" activity for that application opens as the root activity in the stack.
设备的Home页面是大多数task的起始位置。
当用户触摸一个在launcher应用中的图标(或者Home页面中的快捷方式)时,应用的task就会来到前台。
如果这个应用还没有task(这个应用最近没有被使用过),那么一个新的task会被建立并且应用的“主”activity作为stack的根activity被打开。
When the current activity starts another, the new activity is pushed on the top of the stack and takes focus.
The previous activity remains in the stack, but is stopped.
When an activity stops, the system retains the current state of its user interface.
When the user presses the Back button, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored).
Activities in the stack are never rearranged, only pushed and popped from the stack—pushed onto the stack when started by the current activity and popped off when the user leaves it using the Back button.
As such, the back stack operates as a "last in, first out" object structure.
Figure 1 visualizes this behavior with a timeline showing the progress between activities along with the current back stack at each point in time.
当当前activity打开另一个activity时,新的activity会被推入stack的顶部并且获得焦点
前一个activity仍然在stack中,但是处于stopped状态
当一个activity处于stop状态时,系统会保持它当前的UI状态
当用户按back键时,当前的activity从stack顶部弹出(activity会被销毁)并且上一个activity变成resume状态(上一个UI状态被恢复)
stack中的activity绝不会重新排列,在stack中只有压入和弹出 —— 当被当前的activity启动时压入stack,当用户使用back键离开它时弹出。
就其本身而言,back stack操作是像“后进先出”的对象结构一样
下图通过程序在多个activity之间连同当前的back stack适时地在每一个点的时间线展示了这种行为。
Figure 1. A representation of how each new activity in a task adds an item to the back stack.
When the user presses the Back button, the current activity is destroyed and the previous activity resumes.
上图为task中每一个新activity如何向添加一个条目到back stack的展示。
当用户按下back键时,当前的activity被销毁并且恢复上一个activity。
If the user continues to press Back, then each activity in the stack is popped off to reveal the previous one, until the user returns to the Home screen (or to whichever activity was running when the task began).
When all activities are removed from the stack, the task no longer exists.
如果用户继续按back键,那么每一个在stack中的activity都会弹出暴露出上一个activity,直到用户返回到Home(或者退回到task开始时运行的activity)
当所有activity都被从stack中移除之后,task也就不复存在了。
A task is a cohesive unit that can move to the "background" when users begin a new task or go to the Home screen, via the Home button.
While in the background, all the activities in the task are stopped, but the back stack for the task remains intact—the task has simply lost focus while another task takes place, as shown in figure 2.
A task can then return to the "foreground" so users can pick up where they left off.
Suppose, for example, that the current task (Task A) has three activities in its stack—two under the current activity.
The user presses the Home button, then starts a new application from the application launcher.
When the Home screen appears, Task A goes into the background.
When the new application starts, the system starts a task for that application (Task B) with its own stack of activities.
After interacting with that application, the user returns Home again and selects the application that originally started Task A.
Now, Task A comes to the foreground—all three activities in its stack are intact and the activity at the top of the stack resumes.
At this point, the user can also switch back to Task B by going Home and selecting the application icon that started that task (or by touching and holding the Home button to reveal recent tasks and selecting one).
This is an example of multitasking on Android.
task是一个紧密结合的单元,当用户打开一个新的task或者浏览Home主屏时,task可以移动到“后台”
当在后台时,task中所有的activity都是stopped状态,但是task的back stack保持完整,当另一个task占据位置时之前的task只是简单的失去焦点,如上图所示。
task可以返回到前台,所以用户可以回到他们离开的地方。
假设:例如当前的task(task A)在他的stack中有3个activity,其中两个在当前activity下面。
用户按下Home键,然后从launcher应用启动一个新的应用。
当home页面出现的时候,task进入后台。
当新的应用开启时,系统为这个新应用自己的activity的stack开启一个task(Task B)
与新应用交互完成之后,用户返回Home然后选择启动task A的原始应用。
现在,Task A来到前台,stack中的3个activity原封不动没有改变,stack最顶部的activity重新开始。
这时候,用户可以通过去Home选择启动Task B的应用图标转换回到Task B(或者通过长按Home键显示出最近的task,然后选择)
这是一个android上面的多任务的例子。
Note: Multiple tasks can be held in the background at once.
However, if the user is running many background tasks at the same time, the system might begin destroying background activities in order to recover memory, causing the activity states to be lost.
See the following section about Activity state.
注意:多task可以同时进入后台。
然而,如果用户同时运行了很多task在后台,系统也许为了恢复内存而开始销毁后台的activity,导致activty的状态丢失
Because the activities in the back stack are never rearranged, if your application allows users to start a particular activity from more than one activity, a new instance of that activity is created and pushed onto the stack (rather than bringing any previous instance of the activity to the top).
As such, one activity in your application might be instantiated multiple times (even from different tasks), as shown in figure 3.
As such, if the user navigates backward using the Back button, each instance of the activity is revealed in the order they were opened (each with their own UI state).
However, you can modify this behavior if you do not want an activity to be instantiated more than once.
How to do so is discussed in the later section about Managing Tasks.
因为back stack中activity绝不会重新排列,如果你的应用允许用户从多于一个的activity打开一个特别的activity,一个新的这个activity实例被建立并且压入stack中(而不是把这个activity之前的任何实例带到stack顶部)
就其本身而言,你应用中的一个activity也许会被实例化多次(甚至从不同的task中),如上图所示
同样,如果用户用back键导航回退,每一个activity实例会按着他们被打开的顺序依次显露出来(带着他们自己的UI状态)
不管怎样,如果你不希望一个activity被实例化多次你可以修改这种行为。
如果修改将在下面的管理task章节讨论
To summarize the default behavior for activities and tasks:
activity和task的默认行为摘要
When Activity A starts Activity B, Activity A is stopped, but the system retains its state (such as scroll position and text entered into forms).
If the user presses the Back button while in Activity B, Activity A resumes with its state restored.
When the user leaves a task by pressing the Home button, the current activity is stopped and its task goes into the background.
The system retains the state of every activity in the task.
If the user later resumes the task by selecting the launcher icon that began the task, the task comes to the foreground and resumes the activity at the top of the stack.
If the user presses the Back button, the current activity is popped from the stack and destroyed.
The previous activity in the stack is resumed.
When an activity is destroyed, the system does not retain the activity's state.
Activities can be instantiated multiple times, even from other tasks.
当Activity A开启Activity B时,Activity A进入stop状态,但是系统保持Activity自己的状态(比如滚动的位置和文本输入的形式)
在Activity B中如果用户按下back键,Activity A会和它自己的状态一起恢复。
当用户通过按Home键离开一个task时,当前的activity处于stop并且它的task进入后台
系统保持task中每一个activity的状态
如果之后用户通过选择最初打开task的launcher图标打开恢复这个task,task会进入前台并且恢复stack中最顶部的activity。
如果用户按下back键,当前的activity会被从stack中弹出并销毁
上一个stack中的activity被恢复。
当一个activity被销毁后,系统不会保持这个activity的状态
activity可以被实例化多次,甚至从其他的task中。
保存activity的状态
As discussed above, the system's default behavior preserves the state of an activity when it is stopped.
This way, when users navigate back to a previous activity, its user interface appears the way they left it.
However, you can—and should—proactively retain the state of your activities using callback methods, in case the activity is destroyed and must be recreated.
正如上面所讨论的,当activity进入stop状态时,系统默认行为保护activity的状态。
这样,当用户导航回退到上一个activity时,它就会显示离开它时的UI
不管怎样,你可以也应该有意识的用回调函数保存你activity的状态 ,以防activity被销毁并且必须被重新建立
When the system stops one of your activities (such as when a new activity starts or the task moves to the background), the system might destroy that activity completely if it needs to recover system memory.
When this happens, information about the activity state is lost.
If this happens, the system still knows that the activity has a place in the back stack, but when the activity is brought to the top of the stack the system must recreate it (rather than resume it).
In order to avoid losing the user's work, you should proactively retain it by implementing the onSaveInstanceState() callback methods in your activity.
For more information about how to save your activity state, see the Activities document.
当系统停止了你的一个activity时(例如一个新的activity打开了或者task移动到后台),如果需要恢复系统内存的话,系统也许会完全销毁这个activity。
当发生这种情况,这个activity的有关状态的信息将会丢失
如果发生这种情况,系统仍然知道这个activity在back stack占有一个位置,但是当这个activity被带到stack顶端时,系统必须重新建立它(而不是复用它)。
为了避免丢失你的成果,你应该有意识的通过在你的activity中实现onSaveInstanceState()这个回调函数来保持你的成果。
本文来自对下面地址的翻译,英文水平实在有限,希望拍砖同时能给予指正。
http://developer.android.com/guide/components/tasks-and-back-stack.html
转贴请保留以下链接
本人blog地址
相关推荐
通过下载并解压“Z-Stack 3.0.2-.7z”文件,开发者可以获得完整的SDK包,其中包括源代码、库文件、编译工具、示例应用和详细的开发文档,从而开始基于Z-Stack 3.0.2的物联网项目开发。务必仔细阅读文档,理解新特性...
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-...
即使那个activitie可能来自不同的应用,Android也靠着把两个activity保存在同一个任务中来实现这种无缝的用户体验. 一个任务是用户在执行某种工作时所交互的activitie的集合.activitie们放置在一个栈("后退栈")中,...
通过以上步骤,我们可以有效地利用`ndk-stack`工具来解决在Cocos2d-x、JNI以及Android NDK开发过程中遇到的调试难题。尤其是在处理C/C++代码时,能够更加直观地看到函数调用的流程,这对于定位bug具有极大的帮助。...
Task&BackStack;.mmap
**Z-stack开发指南-中文翻译-未纠错** Z-stack是由美国德州仪器(TI)提供的一种专为ZigBee无线网络设计的协议栈。ZigBee是一种基于IEEE 802.15.4标准的低功耗、低数据速率、近距离无线通信技术,广泛应用于智能...
**imsdroid与Android Ngn-stack详解** imsdroid是一个专为Android平台设计的开源项目,它致力于实现IP多媒体子系统(IMS)的功能。IMS是一种基于IP网络的通信架构,主要用于提供传统移动通信网络中的语音、视频通话...
ndk-stack 是一个强大的命令行调试工具,用于调试 Native 代码,especially for Android 平台的.so 库文件。下面我们来详细了解 ndk-stack 在 cocos2d-x 中的应用。 什么是 ndk-stack? ndk-stack 是 Android NDK ...
TI BLE-STACK-CC2540-CC2541是Texas Instruments(TI)公司推出的针对其蓝牙低功耗(Bluetooth Low Energy, BLE)芯片CC2540和CC2541的官方开发库。这个库包含了必要的软件工具和资源,用于开发基于这些芯片的BLE...
1. 解压文件:使用 `tar -zxvf redis-stack-server-6.2.6-v7.rhel7.x86-64.tar.gz` 命令解压。 2. 配置环境:编辑 `/etc/redis/redis.conf` 文件,根据需求调整配置。 3. 启动服务:使用 `systemctl start redis` 或...
在Android应用开发中,Backstack(返回栈)是管理Activity或Fragment导航的关键元素。它允许用户通过按下设备上的后退按钮(或者程序逻辑中触发)来按照历史顺序回溯到先前的界面。Android-SimpleStack项目提供了一...
综上所述,"MTK-stack-and-stack-management-.doc"文档很可能会深入探讨以上知识点在MTK平台上的具体实现和优化策略,对于开发者了解MediaTek设备上的应用开发具有很高的参考价值。通过学习这份文档,开发者将能够更...
- **定义与功能**:Android-NGN-Stack 是一个为 Android 2.x 或更高版本设备设计的下一代网络(NGN)堆栈。该堆栈基于 Doubango 框架,后者是世界上最先进的开源 3GPP IMS/RCS 框架之一,适用于嵌入式系统和桌面系统...
该压缩包中的"Z-Stack-Mesh-1.0.0 (1).exe"文件很可能是Z-Stack-Mesh-1.0.0的安装程序,用于在开发环境中设置和配置ZigBee协议栈。通常,这个安装包会包含以下组件: 1. **开发工具**:如IAR Embedded Workbench或...
《fullstack-react-book-r36》是一本全面且深入的指南,专注于React及其相关的技术生态。这本书旨在帮助读者成为ReactJS领域的专家,提供最新的、详尽的教程和实践指导。以下将详细介绍React及其朋友们的核心概念和...
通过深入阅读和分析这些源码,开发者可以了解Android NGN Stack如何在移动设备上实现高效、可靠的通信服务,并且可以根据自己的需求进行二次开发和创新。无论是对移动通信有兴趣的初学者,还是有经验的开发者,都能...
《fullstack-react-book-r39》是一份关于React技术栈的综合教程,更新至Revision 39,发布日期为2019年1月10日。这份资源涵盖了React库的最新版本16.7,旨在帮助开发者全面理解并熟练掌握React开发技能。 React是...
标题“BLE-STACK-CC2540-CC2541”暗示了这是一个与蓝牙低功耗(BLE,Bluetooth Low Energy)技术相关的软件栈,主要用于Texas Instruments(TI)的CC2540和CC2541微控制器。这两个芯片是TI推出的蓝牙智能系统级芯片...
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 ...
PyPI官网下载的资源“stackmanager-1.2.3-py3-none-any.whl”就是一个这样的软件包,用于安装和管理Python项目中的依赖。 首先,我们来详细了解一下`.whl`文件。这是一种预编译的Python二进制包格式,全称为“Wheel...