2.App Components-activities/tasks and Back Stack

Source: Internet
Author: User
Tags home screen

1. Tasks and Back Stack

An application usually contains multiple activities. Each activity should is designed around a specific kind of action the user can perform and can

Start other activities. For example, an email application might has one activity to show a list of new email. When the user selects an email, a

New activity opens to view the email.

An activity can even start activities this exist in other applications on the device. For example, if your application wants to send a 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 the intent then opens. In this case, the intent are to send a email, so an email application ' s

"Compose" activity starts (if multiple activities support the same intent and 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 e-mail activity was part of your application. Even though the activities may is 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 the users interact with when performing A certain job. The activities is arranged in a stack (the "Back Stack"),

In the order in which each activity is opened

The device Home screen was the starting place for most tasks. When the user touches an icon in the Application Launcher (or a shortcut on the

Home screen), that's application ' s task comes to the foreground. If No task exists for the application (the application have not been used

Recently), then a new task was 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 was pushed on the top of the stack and takes focus< /c1>. The previous activity remains in

the stack, but is stopped. When a activity stops, the system retains the current state of its user interface. When the user presses the

    Back button, the current activity was popped from the top of the stack (the activity is destroyed) and th E Previous activity resumes (the

Previous state of it UI is restored). Activities in the stack is 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 on,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.

    

If the user continues to press back and then each activity in the stack are popped off to reveal the previous one, UN Til the user returns to the Home

Screen (or to whichever activity is running when the task began). When all activities is removed from the stack, the task no longer exists

  The task has a simply lost focus while a 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.

  

  To summarize the default behavior for activities and tasks:

2.App Components-activities/tasks and Back Stack

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.