first, to understand Task
Task as the name implies, the task, each one Android when the app is running, it creates and maintains a task that belongs to itself, and in fact, Task is a container that contains a stack structure, which is often called a fallback stack to hold all current Android The window object that has been created in the app, usually the interface we see is the window object that is at the top of the fallback stack. When we open a new interface, the previous interface (the Window object) is pressed into the stack, giving the top position of the stack to the new interface (the Window object), and when the Window object is closed, the system will first pop up the stack and destroy the object. When the last window object in the stack is ejected from the stack, the fallback stack is empty, and the fallback stack is destroyed and the application stops. (It should be noted that at this point, the application does not completely exit memory, and some of its resources, such as static variables, also stay in memory for a long time.) )
It is also important to note that each application has a unique Task,When you open a new app, it'sTaskappear in the foreground, displayed to the user, while the oldTaskwill be transferred to the background, the system will automatically save the oldTaskThe state of the window object, etc.Taskafter being re-switched to the foreground, the window responds to the focus and restores all the states, however. It's important to point out that you don't think you're backstageTaskwill stay in memory and wait for you to come back. When the phone memory is exhausted, or a new one is openedAPPWhen you need a lot of memory, you think you'll be waiting for your oldTaskwill be ruthlessly killed by the system, whichTaskThe longer it is stopped, the longer it is destroyed.
two or four startup modes Launchmode
There are four modes of loading for activity:
Set the location of the activity element's Android:launchmode property in the Androidmanifest.xml file:
Mode |
Specific description |
| standard |
The default value for the Launchmode, which is the default when you create a new activity startactivity back finish () in your code method, or it persists until the app stops. A new instance is generated, regardless of whether an existing instance exists. |
Singletop |
if the instance of the window is exactly at the current interface (that is, the stack top of the fallback stack), the system will no longer create a new Window object ( Standard mode is different, whether it is a new stack or not, the window instance will be used directly. The advantage of this is that as long as the required instance is always on the interface, there is only one instance in the fallback stack, and the next time you exit (because there is only one Window object), this mode is particularly suitable for use in NFC . if a corresponding activity instance is found to be at the top of the stack, it is reused and no new instances are generated. However, note that it only looks at the top of the stack, not look at the stack , if the top of the stack does not have the instance, the stack also has, it will still create a new Window object instance. |
| singletask |
This model is more powerful and overbearing, that Other activity instances above the activity instance are all out of the stack   |
SingleInstance |
This mode is more arbitrary, if there is a current fallback stack, then all its previous instance objects are cleared, and then placed on top of the stack, if the current fallback stack does not, it will create a new fallback stack, and then create a new instance object, and not allow other instance objects to come in. This mode is rarely used because a new fallback stack that is used only for one instance object is too much memory space. And it doesn't make much sense. |
the above text is rather dull, and there is no specific example. The reason for not writing an example is because a senior has written a very detailed analysis of the case. If you still don't understand, please read this blog post. http://blog.csdn.net/liuhe688/article/details/6754323
In addition, upload a routine that is specifically designed to tell you about four different modes. is an example in the authoritative guide for Android development, and everyone can run to see if that's the case.
Routine download