About the android process of the online information is relatively small, in fact, the application layer programmer, rarely touch the process, the thread is often encountered.
The life cycle of a process
Android will try to keep the app going, but sometimes it will remove some of the old processes in order to reclaim some memory space for new processes and more important processes.
To determine which processes are left and which processes are killed, the system assigns a priority level to each process based on the state of the components and components that are running in the process.
The lowest priority process is first killed.
The hierarchy of importance of this process has five levels , the following list of these five processes, in accordance with the importance of the arrangement, the most important in the first place.
A Foreground process Foreground processes
Foreground Process is the process that the user is currently doing, and if one of the following conditions is met, a process is considered to be at the foreground:
1. The process holds an activity that is interacting with the user (the activity is in the Onresume () state).
2. The process holds a service that the service and the user are interacting with activity bindings.
3. The process holds a service that is running in the foreground, that is, it is called startForeground()
.
4. The process holds a service that is executing its life cycle callback function (,, onCreate()
onStart()
or onDestroy()
).
5. The process holds a broadcastreceiver, and the Broadcastreceiver is implementing its onReceive()
approach.
Killing the foreground process requires user interaction because the foreground process has the highest priority.
Two Visible process
If a process does not contain any foreground components, but still affects what the user can see on the screen, Visible Processes .
The visible process meets one of the following conditions:
1. The process holds an activity, which is not in the foreground, but is still visible to the user (in the onPause () call and does not call the onStop () state).
This happens when, for example, the activity in the foreground opens a dialog box so that the activity is visible later.
2. The process holds a service, which is bound to a visible (or foreground) activity.
Visible processes are also considered important and are generally not destroyed unless the visible process has to be killed to ensure that all foreground processes are running.
Three Services Process Service Processes
If a service is running in a process that is startService()
open and not part of the above two higher priorities, the process is a process of servicing .
Although the service process is not tied to what the user can see, they are generally doing things that the user cares about, such as playing music in the background, downloading data in the background, and so on.
Four Background processes Background Process
If the process does not belong to the above three cases, but the process holds an activity that the user is not visible ( onStop () of the activity is called, but OnDestroy () does not have a status of the call), the process is considered a Background Process .
Background processes do not directly affect the user experience, and the system kills background processes for foreground processes, visible processes, and service processes.
Often there are a number of background processes that are stored in an LRU (least Recently used) list, which ensures that the activity that the user recently used was finally destroyed, which is the activity that was first destroyed at the farthest time.
Five Empty process
If a process does not contain any active application components, it is considered Empty Process .
The only reason to save this process is to cache the need , in order to speed up the next time when the component in this process starts.
The system often kills empty processes in order to balance the process cache with the resources cached by the underlying kernel.
Related instructions
1.Android will place the process at a high priority whenever possible.
For example, a process that has a visible state of activity and a service is considered a visible process, not a servicing process.
2. The level of one process may be increased by the dependency of other processes, and a process serving another process will not have a lower priority than the process it serves.
For example, a content provider in a process provides services to a customer in a B process, or a service in a process is bound to a component in a B process, the priority of a process is at least the priority of the B process is as high.
3. Because the service process has a higher priority than the background process, it is better to open a service than to create a worker thread for an activity that requires a long-time operation, especially if the operation is likely to exceed the duration of the activity.
For example, to upload an image file, you should open a service to upload the work, so that when the user leaves the activity is still working. Using the service will ensure that the operation has at least the priority of the servicing process.
Resources
Sandy Zhang android in-depth video tutorial-process life cycle.
API Guides:processes and Threads
Http://developer.android.com/guide/components/processes-and-threads.html
Http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0628/1400.html