任务和返回栈

Tasks and Back Stack

任务和返回栈

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. For example, an email app might have one activity to show a list of new messages. When the user selects a message, a new activity opens to view that message. This new activity is added to the back stack. If the user presses the Back button, that new activity is finished and popped off the stack. The following video provides a good overview of how the back stack works.

任务是执行某一确定任务时与用户交互的Activity集合。按照每个Activity打开的顺序,这些Activity被排列到一个堆栈----返回栈中。例如,一个邮件app可能有一个显示新消息列表的Activity。当用户选择一条消息,打开一个新的Activity去显示该消息。这个新的Activity会被添加到返回栈。如果用户按下返回按钮,这个Activity会结束运行并从返回栈弹出。下面的视频提供了一个关于堆栈如何工作的良好概述。

When apps are running simultaneously in a multi-windowed environment, supported in Android 7.0 (API level 24) and higher, the system manages tasks separately for each window; each window may have multiple tasks. The same holds true for Android apps running on Chromebooks: the system manages tasks, or groups of tasks, on a per-window basis.

当多个app同时运行在多窗口环境中,在Android 7.0和更高级别下,系统分别为每个窗口管理任务;每个窗口可能有多个任务。这同样适用于Android app运行在Chromebooks上:系统在每个窗口基础上管理任务或一组任务。

The device Home screen is the starting place for most tasks. When the user touches an icon in the app launcher (or a shortcut on the Home screen), that app's task comes to the foreground. If no task exists for the app (the app has not been used recently), then a new task is created and the "main" activity for that app opens as the root activity in the stack.

设备主屏幕是大多任务开始的地方。当用户触摸应用程序启动器图标(或者主屏幕的快捷方式)时,app的任务会出现在前台。如果app没有任务存在(app近期没有被使用过),然后创建一个新任务,并将该应用程序的“主”活动作为堆栈中的根活动打开。

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.

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.

当当前的Activity启动另一个Activity时,新的Activity被压入栈顶并获取焦点。原来的Activity仍然保留在栈里面,但是是停止状态。当Activity停止时,系统保留了用户界面的当前状态。当用户按下返回按钮时,当前Activity从堆栈顶部弹出(Activity被销毁)并且原来的Activity重新恢复(恢复它之前的UI状态)。堆栈中的Activity永远不会重新排列,仅仅只会被从栈里压入或者弹出——当从当前Activity启动的时候入栈并且当用户使用返回按钮离开的时候出栈。像这样的,返回栈操作类似“后进先出”的对象结构。



猜你喜欢

转载自blog.csdn.net/agoddog/article/details/79910759
今日推荐