Assignment of task stacks in Android

Source: Internet
Author: User

First, let's look at the definition of task, which is how Google defines a task: a task is something, the user experiences as an "application." It's a group of related activities, arranged in a stack. A task is a stack of activities, not a class or an element in the manifest file. This means that the task is actually an activity stack, and usually a application that the user feels is a task. From this definition, the task is not connected to the service or any other components, it is only for the activity.
Activity has different startup modes that can affect the assignment of a 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 no more activity,task ends in the stack.
event task Stack (bold is the top component)
Click to open the email application and enter the Inbox (Activity A) A
Select an email and click View Details (Activity B) a B
Click Reply to start writing new mail (Activity C) ab C
Write a few lines, click Select Contacts, Go to the Select Contact interface (Activity D) abc D
Select contacts, continue to write messages ab C
write messages, send complete, return to original message a B
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,
What a gorgeous 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
Standard "," Singletop "," Singletask "," singleinstance ".
 
standard mode , which is the default, is the normal task mode, and with no other factors, activity using this mode constructs an instance of activity that is added to the caller's task stack, The standard mode is undoubtedly the most appropriate for an activity that uses a general overhead generally, because it is logically simple and clear, so it is the default choice.
 
the singletop model , which is basically consistent with the standard, differs only when the requested activity is at the top of the stack. At this point, the activity configured as Singletop no longer constructs a new instance into the task stack, but instead sends the new intent to the top of the stack activity, The activity at the top of the stack can be overloaded with onnewintent to deal with new intent (or, of course, ignore ...). )。 This mode reduces some of the duplication overhead at the top of the stack, and avoids some bizarre behavior (imagine how the user experience would be if several of the same activities were the same activity at the top of the stack, and then the first level exits) ... ), well suited to some of the list activity shows that will have an update. A living example is that the browser (Browser) bookmarks activity (browserbookmarkpage) is used in the Android default app, Singletop.
 
Singletask, and singleinstance, then all take the other task of trail.
The activity marked as singletask , at most one instance exists, and is located in the task with which it is rooted. All requests for the activity are skipped to the activity's task. Singletask, much like the concept of a single-piece pattern, all modifications are based on an instance, which is often used in activity where the construction cost is large but the switching cost is small. The most typical example is the main activity of the browser application (named Browser ...). ), which is the window that displays the current tab content of the current page. Its construction cost is large, but the page switch or is faster, in the Singletask match, or quite in a fit of heaven.
 
singleinstance seems more extreme. Most of the time singleinstance and Singletask are exactly the same, the only difference being that the activity of singleinstance is the only activity in its stack, and if other activity is involved, are transferred to other tasks. This makes SingleInstance's activity, like an island, a complete black box, which does not care about where the request comes from or who is to follow. In the Android default application, very few such activity, in my personal engineering practice, has tried to Youdao dictionary in the fast Word activity used,
It is because I feel that the quick access to the word entry is convenient (from notification) and will be used in every situation and should be completely independent.
 
big apk is broken into a lot of small apk
Android:affinity property of activity
1. After the configuration when the activity is started to find out if there is no activity affinity attribute the same as to join this
the activity is not on the task of the new mission
2.affinity function requires a condition that has one:
1.intent contains flag_activity_new_task tags
the 2.activity element has the Allowtaskreparenting property enabled.

Assignment of task stacks in Android

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.