[Introduction to Android]android Task Task]

Source: Internet
Author: User

http://blog.csdn.net/guomeijuan916/article/details/8121468

About the components and applications in Android, previously involved, mostly static concepts. When an application runs, it is inevitable that you will need to be concerned about the concepts of processes and threads.  In Android, the dynamic operation of components, there is a most unusual concept, is the task, translated into tasks, should be more logical. Task intervention, the most important role is the connection between components, from the details of the process concept, can be configured with a different model of things, in many cases, can simplify the understanding of the upper level developers to help you better develop and configure

Task

In the SDK for Task (Guide/topics/fundamentals.html#acttask), there is a good analogy, that the task is equivalent to the concept of application (application).  In the eyes of developers, the development of an Android program is to do a single detached family component, but for the average user, they perceive is only a running overall application, the whole behind, is the task. Task, simply put, is a collection of activity components that are clustered together in a stack of patterns. They have potential pre-and post-drive associations, the newly added activity component, at the top of the stack, and only activity at the top of the stack, before they have the opportunity to interact with the user. When the activity at the top of the stack completes its mission, the task will pull it out and let the next activity that will run to the top of the stack come to the user until there is no more activity,task end in the stack.

Event Task Stack

Click to open the email application and enter the Inbox (Activity a) a

Select an email, click View Details (Activity B) AB

Click Reply to start writing new mail (Activity C) ABC

Write a few lines of text, click Select Contacts, go to select Contact Interface (Activity D) ABCD

Select a contact, continue to write e-mail ABC

Write good mail, send complete, back to original mail AB

Click Back to return to Inbox A

Exit email program NULL

As shown in the table above, is an instance. The task stack changes from the beginning of the user's entry to the mailbox to the completion of the reply, exiting the application process. This is a standard stack mode, and for most situations, such a task model is enough to cope, but it can be a lot more brutal when it comes to actual performance, overhead, and so on. For example, starting a browser, in Android is a heavy process, it needs to do a lot of initialization work, and there will be no small memory overhead. But at the same time, using the browser to open some content, but also the general application will have a demand. Imagine, if there are 10 running applications (which will correspond to multiple tasks), you need to start the browser, it will be a cruel scene, 10 task stacks are stacked with very similar browser activity, is how gorgeous a kind of waste ah. So you have the idea that browser activity can exist as a single task, regardless of the request from that task, the browser's task will not be merged into the past. In this way, although the browser activity itself needs to maintain more state, but the overall cost will be greatly reduced, this home for everyone's behavior, or is worthy of praise

Launchmode (boot mode)
1. Standard mode
1) When you start an activity from a task, the new instance of the activity is always in the current
Task is created in
2) A new instance of the activity class will be created each time the activity is started
3) Multiple instances of the same activity can exist in a task
4) Multiple instances of an activity can appear in multiple task stacks
2, Singletop
1) If the activity instance set to Singletop in startup mode is not at the top of the stack,
The performance is consistent with the activity that the startup mode is set to standard
2) If the startup mode is set to Singletop, the instance of activity is at the top of the stack
, a new instance of the activity is not created. Just call the activity at the top of the stack
The Onnewintent method of the instance that passes the new intent to the instance.
3, Singletask
1) activity that is set to Singletask, has global uniqueness, in the Android system
Only one instance of the activity can be created.
2) If Start S is set to singletask activity, the activity's
instance, it frees all activity instances on top of the instance and brings the instance back to
Top of the stack, and the caller Onnewintent method to pass the new intent to the instance
3) When creating an instance of activity that is set to Singletask mode, if the current task's
Taskaffinity is consistent with the activity's taskaffinity, it is directly in the current task
Created if the taskaffinity value of the current task is inconsistent with the taskaffinity of the activity
You create an instance of the activity in a new task.
4, SingleInstance
1) When you create an activity that is set to SingleInstance mode, always create in a new task
2) activity that is set to SingleInstance mode has global uniqueness. On the Android system
Only one instance of the activity can exist in the
3) activity that is set to SingleInstance mode is always present alone in a task
This means that there is no other activity in the task stack where the activity is located.

[Introduction to Android]android Task Task]

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.