Activities and Tasks
As noted earlier, one activity can start another, including one defined in a different application. Suppose, for example, that you'd like to let users display a street map of some location. There's already an activity that can do that, so all your activity needs to do is put together an Intent object with the required information and pass it to startActivity(). The map viewer will display the map. When the user hits the BACK key, your activity will reappear on screen.
翻译:之前我们说过一个 activity 可以启动另外一个activity,即使是其他应用中的activity也可以被启动 . 假定:你希望让你的应用能为用户显示一条街道的地图信息,那么在你的activity中,需要做的就是给startActivity()方法传入一个intent对象来激活一个map viewer activity,这个map viewer activity 将为用户显示一条街道的地图信息。当用户按下BACK按钮时候你的activity重新出现在屏幕上。
To the user, it will seem as if the map viewer is part of the same application as your activity, even though it's defined in another application and runs in that application's process. Android maintains this user experience by keeping both activities in the same task. Simply put, a task is what the user experiences as an "application." It's a group of related activities, arranged in a stack. The root activity in the stack is the one that began the task — typically, it's an activity the user selected in the application launcher. The activity at the top of the stack is one that's currently running — the one that is the focus for user actions. When one activity starts another, the new activity is pushed on the stack; it becomes the running activity. The previous activity remains in the stack. When the user presses the BACK key, the current activity is popped from the stack, and the previous one resumes as the running activity.
翻译:对于用户而言,看上去似乎map viewer是和前面一个activity都是这个应用程序的的组成部分,而事实上这个map viewer完全可能是归属另外一个应用的进程。 Android 能够提供这样的用户体验是通过把两个activities保持在同一个task中实现的. 简单地说,task是用户体验的“应用”,一个 task 可以理解为安放在一个堆栈中的一组相关联的activities,这个堆栈中的根activity是开始这个task的起点 — 这个activity也常常是用户在应用发射台选定的activity。当一个activity启动了另外一个新的activity, 这个新的activity就被压入堆栈,成为当前运行的activity. 先前那个activity 依然保留在堆栈中. 当用户按下 BACK 键, 当前运行的activity弹出堆栈,先前保留在堆栈中的那个activity重新变成当前运行的activity.
The stack contains objects, so if a task has more than one instance of the same Activity subclass open — multiple map viewers, for example — the stack has a separate entry for each instance. Activities in the stack are never rearranged, only pushed and popped.
翻译:堆栈用来存放activity对象,所以如果说一个task中有一个Activity的多个实例的话,比如打开了多个map viewers,每个map viewers实例都是分别压入当前task堆栈的,堆栈从不会对其中的实例顺序重新排列的,堆栈做的只是简单的压入和弹出实例。
A task is a stack of activities, not a class or an element in the manifest file. So there's no way to set values for a task independently of its activities. Values for the task as a whole are set in the root activity. For example, the next section will talk about the "affinity of a task"; that value is read from the affinity set for the task's root activity.
翻译:task是由一组 activities 实例组成的堆栈,它既不是类也不是manifest文件中的元素,所以,如果要修改或约定一个task的某些行为方式必须依赖这个task(堆栈)中的 activity。具体说是要通过task堆栈中的根activitiy来实现对当前task行为方式的特殊约定。比如task的affinity属性值就需要设定在根activity上。
All the activities in a task move together as a unit. The entire task (the entire activity stack) can be brought to the foreground or sent to the background. Suppose, for instance, that the current task has four activities in its stack — three under the current activity. The user presses the HOME key, goes to the application launcher, and selects a new application (actually, a new task). The current task goes into the background and the root activity for the new task is displayed. Then, after a short period, the user goes back to the home screen and again selects the previous application (the previous task). That task, with all four activities in the stack, comes forward. When the user presses the BACK key, the screen does not display the activity the user just left (the root activity of the previous task). Rather, the activity on the top of the stack is removed and the previous activity in the same task is displayed.
翻译:task中的所有activities是作为一个整体出现在前台或是退到后台,例如task1有四个Activity在该task的堆栈中,其他三个Activity在当前运行显示的Activity下面。如果这时用户按下HOME键,屏幕将显示应用发射台界面。然后用户选中另一个应用,实际上Android系统就开始了一个新的task2,这时候之前的那个task1便退到后台,用户这时候看到的task2的根Activity界面,此时,用户可能又按下HOME键,重新选中之前那个应用,这时候task1堆栈重新来到前台,这个task1有四个Activity在自己的堆栈中,此时用户可能又按下BACK键,此时刚才显示过的那个task2的根Activity界面是不会显示出来的,实际显示的将是task1的堆栈中上一次显示过的那个 Activity的界面。总结一下,这里我们要说明的是,任何一个task堆栈中的实例都是作为一个整体来到前台或是退到后台的,用户按下BACK键将只会导致前台所关联的那个task堆栈排列顺序发生变化。
The behavior just described is the default behavior for activities and tasks. But there are ways to modify almost all aspects of it. The association of activities with tasks, and the behavior of an activity within a task, is controlled by the interaction between flags set in the Intent object that started the activity and attributes set in the activity's <activity> element in the manifest. Both requester and respondent have a say in what happens.
翻译:以上描述的规则是activities和task的默认规则,但是这个规则不是说一成不变的,是可以被修改的。要修改这个规则需要在触发 Activity的intent对象中设定flag属性值或者是设定manifest文件中Activity组件元素的相关属性值。
针对这个规则的修改,可能用来设定Intent对象的flags属性的值主要是以下几个:
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
FLAG_ACTIVITY_SINGLE_TOP
针对这个规则的修改,涉及到manifest文件中Activity组件元素的这几个属性:
taskAffinity
launchMode
allowTaskReparenting
clearTaskOnLaunch
alwaysRetainTaskState
finishOnTaskLaunch
The following sections describe what some of these flags and attributes do, how they interact, and what considerations should govern their use.
As noted earlier, one activity can start another, including one defined in a different application. Suppose, for example, that you'd like to let users display a street map of some location. There's already an activity that can do that, so all your activity needs to do is put together an Intent object with the required information and pass it to startActivity(). The map viewer will display the map. When the user hits the BACK key, your activity will reappear on screen.
翻译:之前我们说过一个 activity 可以启动另外一个activity,即使是其他应用中的activity也可以被启动 . 假定:你希望让你的应用能为用户显示一条街道的地图信息,那么在你的activity中,需要做的就是给startActivity()方法传入一个intent对象来激活一个map viewer activity,这个map viewer activity 将为用户显示一条街道的地图信息。当用户按下BACK按钮时候你的activity重新出现在屏幕上。
To the user, it will seem as if the map viewer is part of the same application as your activity, even though it's defined in another application and runs in that application's process. Android maintains this user experience by keeping both activities in the same task. Simply put, a task is what the user experiences as an "application." It's a group of related activities, arranged in a stack. The root activity in the stack is the one that began the task — typically, it's an activity the user selected in the application launcher. The activity at the top of the stack is one that's currently running — the one that is the focus for user actions. When one activity starts another, the new activity is pushed on the stack; it becomes the running activity. The previous activity remains in the stack. When the user presses the BACK key, the current activity is popped from the stack, and the previous one resumes as the running activity.
翻译:对于用户而言,看上去似乎map viewer是和前面一个activity都是这个应用程序的的组成部分,而事实上这个map viewer完全可能是归属另外一个应用的进程。 Android 能够提供这样的用户体验是通过把两个activities保持在同一个task中实现的. 简单地说,task是用户体验的“应用”,一个 task 可以理解为安放在一个堆栈中的一组相关联的activities,这个堆栈中的根activity是开始这个task的起点 — 这个activity也常常是用户在应用发射台选定的activity。当一个activity启动了另外一个新的activity, 这个新的activity就被压入堆栈,成为当前运行的activity. 先前那个activity 依然保留在堆栈中. 当用户按下 BACK 键, 当前运行的activity弹出堆栈,先前保留在堆栈中的那个activity重新变成当前运行的activity.
The stack contains objects, so if a task has more than one instance of the same Activity subclass open — multiple map viewers, for example — the stack has a separate entry for each instance. Activities in the stack are never rearranged, only pushed and popped.
翻译:堆栈用来存放activity对象,所以如果说一个task中有一个Activity的多个实例的话,比如打开了多个map viewers,每个map viewers实例都是分别压入当前task堆栈的,堆栈从不会对其中的实例顺序重新排列的,堆栈做的只是简单的压入和弹出实例。
A task is a stack of activities, not a class or an element in the manifest file. So there's no way to set values for a task independently of its activities. Values for the task as a whole are set in the root activity. For example, the next section will talk about the "affinity of a task"; that value is read from the affinity set for the task's root activity.
翻译:task是由一组 activities 实例组成的堆栈,它既不是类也不是manifest文件中的元素,所以,如果要修改或约定一个task的某些行为方式必须依赖这个task(堆栈)中的 activity。具体说是要通过task堆栈中的根activitiy来实现对当前task行为方式的特殊约定。比如task的affinity属性值就需要设定在根activity上。
All the activities in a task move together as a unit. The entire task (the entire activity stack) can be brought to the foreground or sent to the background. Suppose, for instance, that the current task has four activities in its stack — three under the current activity. The user presses the HOME key, goes to the application launcher, and selects a new application (actually, a new task). The current task goes into the background and the root activity for the new task is displayed. Then, after a short period, the user goes back to the home screen and again selects the previous application (the previous task). That task, with all four activities in the stack, comes forward. When the user presses the BACK key, the screen does not display the activity the user just left (the root activity of the previous task). Rather, the activity on the top of the stack is removed and the previous activity in the same task is displayed.
翻译:task中的所有activities是作为一个整体出现在前台或是退到后台,例如task1有四个Activity在该task的堆栈中,其他三个Activity在当前运行显示的Activity下面。如果这时用户按下HOME键,屏幕将显示应用发射台界面。然后用户选中另一个应用,实际上Android系统就开始了一个新的task2,这时候之前的那个task1便退到后台,用户这时候看到的task2的根Activity界面,此时,用户可能又按下HOME键,重新选中之前那个应用,这时候task1堆栈重新来到前台,这个task1有四个Activity在自己的堆栈中,此时用户可能又按下BACK键,此时刚才显示过的那个task2的根Activity界面是不会显示出来的,实际显示的将是task1的堆栈中上一次显示过的那个 Activity的界面。总结一下,这里我们要说明的是,任何一个task堆栈中的实例都是作为一个整体来到前台或是退到后台的,用户按下BACK键将只会导致前台所关联的那个task堆栈排列顺序发生变化。
The behavior just described is the default behavior for activities and tasks. But there are ways to modify almost all aspects of it. The association of activities with tasks, and the behavior of an activity within a task, is controlled by the interaction between flags set in the Intent object that started the activity and attributes set in the activity's <activity> element in the manifest. Both requester and respondent have a say in what happens.
翻译:以上描述的规则是activities和task的默认规则,但是这个规则不是说一成不变的,是可以被修改的。要修改这个规则需要在触发 Activity的intent对象中设定flag属性值或者是设定manifest文件中Activity组件元素的相关属性值。
针对这个规则的修改,可能用来设定Intent对象的flags属性的值主要是以下几个:
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
FLAG_ACTIVITY_SINGLE_TOP
针对这个规则的修改,涉及到manifest文件中Activity组件元素的这几个属性:
taskAffinity
launchMode
allowTaskReparenting
clearTaskOnLaunch
alwaysRetainTaskState
finishOnTaskLaunch
The following sections describe what some of these flags and attributes do, how they interact, and what considerations should govern their use.
发表评论
-
Intents and Intent Filters--Intent filters
2010-09-03 10:21 1361Intent filters To inform ... -
Intents and Intent Filters---Intent Resolution
2010-09-03 09:45 1196Intent Resolution Intents 可以分成 ... -
Intents and Intent Filters---Intent Objects
2010-09-02 11:15 816Intent Objects An Intent ... -
Intents and Intent Filters---序言
2010-09-01 16:06 872Intents and Intent Filters Key ... -
Application Fundamentals--Processes and lifecycles(进程生命周期)
2010-08-30 09:23 753Processes and lifecycles---进 ... -
Application Fundamentals--Broadcast receiver lifecycle(广播接收组件生命周期)
2010-08-30 09:20 4243Broadcast receiver lifecycle--- ... -
Application Fundamentals--Service lifecycle(服务组件的生命周期)
2010-08-30 09:18 1049Service lifecycle--服务组件的生命周期 A ... -
Application Fundamentals--Coordinating activities(activity实例间协调)
2010-08-30 09:15 966Coordinating activities---activ ... -
Application Fundamentals--Saving activity state(保存activity实例的状态信息)
2010-08-27 10:06 1257Saving activity state--保存activi ... -
Application Fundamentals--Component Lifecycles(组件生命周期)
2010-08-27 09:56 959Component Lifecycles--组件生命周期 A ... -
Application Fundamentals--Thread-safe methods(线程安全方法)
2010-08-27 09:51 1254Thread-safe methods--线程安 ... -
Application Fundamentals--Remote procedure calls(远程过程调用)
2010-08-27 09:41 1290Remote procedure calls--远程过程调用 ... -
Application Fundamentals--Processes and Threads(进程与线程)
2010-08-27 09:36 990Processes and Threads--进程 ... -
Application Fundamentals--Starting tasks
2010-08-27 09:34 699Starting tasks An activity is ... -
Application Fundamentals--Clearing the stack(堆栈清理)
2010-08-27 09:28 1344Clearing the stack--堆栈清理 If th ... -
Application Fundamentals--Launch modes-启动模式
2010-08-27 09:27 1117Launch modes-启动模式 There are fo ... -
Application Fundamentals--Affinities and new tasks
2010-08-27 08:45 979Affinities and new tasks By de ... -
Application Fundamentals--Intent 过滤器
2010-08-27 08:41 921Intent 过滤器 Intent 对象可以显式指定目标组件 ... -
Application Fundamentals--The manifest file
2010-08-27 08:40 788The manifest file Android启动应用程 ... -
Application Fundamentals--Activating components: intents(组件的激活)
2010-08-27 08:38 934Activating components: intents- ...
相关推荐
DB2 9 Database and Application Fundamentals - Academic Initiative 000-302 2011年12月版本 V8.02 Q188道。
fundamentals-of-power-electronics_2nd_erickson_full
Fundamentals-of-heat-and-mass-transfer 7ed.pdf ;INSTRUCTOR'S SOLUTIONS MANUAL
信息与通信工程专业毕业设计说明外文翻译--Fundamentals-of-Time-and-Frequency.doc
Fundamentals-of-HVAC-Control-Systems-Malestrom.part02.rar
linux-shell-scripting-fundamentals-bash.epub
fundamentals-of-radar-signal
ios-12-programming-fundamentals-swift epub. very good
Android UI Fundamentals - Develop and Design for Android application development
此存储库包含
fundamentals-of-statistical-signal-processing-volume-i-estimation-theory_1
2016-fuel cell fundamentals-3rd edition.pdf
Az-900-Microsoft-Azure-Fundamentals-Version-16.0-It-Exam-Practice-Test.pdf
Az-900-Microsoft-Azure-Fundamentals-Version-19.1-It-Exam-Practice-Test.pdf
Data Warehousing Fundamentals-2001
Electric Machinery Fundamentals - 5th Ed
Kubernetes 基础课程个人笔记整理包含内容:01....08.卷和数据(Volumes and Data) 09.服务(services) 10. INGRESS 11.Scheduling 12.记录和故障排除(Logging and Troubleshooting) 13.Custom Resource Definit
安卓应用开发教程配套实验教程!课程网址:https://developer.android.com/courses/fundamentals-training/toc-v2