`

Tasks and Back Stack

阅读更多
Even though the activities may be from different applications, Android maintains this seamless user experience by keeping both activities in the same 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.

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.

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 key, 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 key. As such, the back stack operates as a "last in, first out" object structure.

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.

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

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

•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 key while in Activity B, Activity A resumes with its state restored.
•When the user leaves a task by pressing the HOME key, 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 key, 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.

you can use these manifest attributes and intent flags to define how activities are associated with tasks and how the behave in the back stack.

Launch modes allow you to define how a new instance of an activity is associated with the current task.

As such, if Activity A starts Activity B, Activity B can define in its manifest how it should associate with the current task (if at all) and Activity A can also request how Activity B should associate with current task. If both activities define how Activity B should associate with a task, then Activity A's request (as defined in the intent) is honored over Activity B's request (as defined in its manifest).

Some the launch modes available in the manifest are not available as flags for an intent and, likewise, some launch modes available as flags for an intent cannot be defined in the manifest.

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.

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.
分享到:
评论

相关推荐

    Android学习笔记-Activity篇

    Android学习笔记-Activity篇 Contents Android学习笔记-Activity篇 1 ...Tasks and Back Stack 4 一、管理Task 4 1.1 定义launch模式 4 1.2 设置affinities 5 1.3 清空the back stack 5 1.4 开始task 5

    Professional.Csharp.6.and..NET.Core.1.0.11190

    The new updates can actively streamline your workflow, with major changes including reimagined C# refactoring support, a new .NET Web app stack, and the .NET compiler platform that makes C# and Visual...

    AAA and Network Security for Mobile Access.pdf

    (IP) and TCP/IP stack layering concepts. Except for the above, most of the other IP-related concepts are explained in the text. Thus, the book is suitable for managers, engineers, researchers and ...

    OpenStack Trove Essentials(PACKT,2016)

    We then look at how to provision databases in self-service mode, and how to perform administration tasks such as backup and recovery, and fine-tuning databases. At the end of the book, we will ...

    OpenStack.Trove.Essentials.1785285610.pdf

    Back up and restore your databases with the help of Trove In Detail OpenStack has become an extremely popular solution to build public and private clouds with. Database as a Service (DBaaS) enables ...

    Mastering ROS for Robotics Programming - Second Edition[www.rejoiceblog.com].pdf

    chapter explains how to record and play back messages using rosbag and rqt_bag. Chapter 4, 3D Modeling and Simulation, constitutes one of the first steps in order to implement your own robot in ROS. ...

    The Indispensable PC Hardware Book - rar - part1. (1/7)

    Stack segment and stack pointer. Data segment DS and addressing. Addressing types and instruction coding. Programming at processor level: mnemonics and the assembler. Addressing types. ...

    Script Inspector 3 v3.0.30

    =) Programmers can finally focus on their tasks instead of waiting for (and sometimes fighting with) the external IDE’s to run, load the correct script, or jump to the correct line. Main features: ...

    Introduction.to.Android.Application.Development(4th,2013.12) pdf

    Way Back When 11 “The Brick” 13 Wireless Application Protocol (WAP) 15 Proprietary Mobile Platforms 17 The Open Handset Alliance 18 Google Goes Wireless 18 Forming the Open Handset Alliance 19 ...

    Microsoft Library MSDN4DOS.zip

    9.6 Interrupt Tasks and Interrupt Procedures 9.7 Error Code 9.8 Exception Conditions 9.9 Exception Summary 9.10 Error Code Summary Chapter 10 Initialization 10.1 Processor State After Reset 10.2 ...

    计算机网络第六版答案

    23. The five layers in the Internet protocol stack are – from top to bottom – the application layer, the transport layer, the network layer, the link layer, and the physical layer. The principal ...

    带优先级的多任务管理模块(C)

    If the task fails, the first move to a place, over time retry the put back, and so on ... There are many possible places to use it ... so, still retained 2. How many tasks can be complicated to ...

    Microsoft Visual C# 2013 Step by Step,最新资料

    Your hands-on guide to Visual C# fundamentals Expand your expertise—and teach yourself the fundamentals of Microsoft Visual C# 2013. If you have previous ...Using the stack and the heap 197 vu Contents

    a project model for the FreeBSD Project.7z

    After providing definitions of terms used, this document will outline the organisational structure (including role descriptions and communication lines), discuss the methodology model and after ...

    servlet2.4doc

    Creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. Cookie(String, String) - Constructor for class javax....

Global site tag (gtag.js) - Google Analytics