Process level in Android

Source: Internet
Author: User

In Android, all components of the same app run in the same process by default, but you can also specify which process the component will run by modifying the Android:process property in the manifest file, or let the components of different applications run in the same process. Of course, these apps share a user ID and have the same digital certificate.

Android may decide to shut down a process at some point, and when it decides to close those processes, the system will measure how closely each process is to the user, and this is related to the level of progress in Android. Processes like a visible activity have higher levels than those that are invisible to the activity, and are less likely to be killed by the system. So what are the android process levels? First, we can look at a picture:

The images above are the different types of processes and their priorities in the Android system. The following is an introduction to each process.

1. Foreground process

The user is currently doing something that requires this process. If one of the following conditions is met, a process is considered a foreground process:

the process has an activity that is interacting with the user (the Onresume () method of the activity is called).

This process has a service that is bound to an activity that is interacting with the user.

This process has a service that is running in the foreground (the service calls Method Startforeground ()).

This process has a service that is performing any of its life cycle callback methods (OnCreate (), OnStart (), or OnDestroy ()).

This process has a broadcastreceiver that is executing its onreceive () method.


Typically, at any point in time, only a few foreground processes exist. They are only killed when they reach a contradiction that cannot be adjusted-such as when the memory is too small to continue running. Usually, by this time, the device has reached a memory paging state, so need to kill some foreground process to ensure the user interface response

2. Visible process

A process does not have components running in the foreground, but it can still affect what the user sees. The process is visible when the following conditions are true:

This process has an activity that is not in the foreground but is still visible (its OnPause () method is called). This happens when a foreground activity launches a dialog box.

3. Service Process

A visible process is considered to be extremely important. And, unless you kill it, you can guarantee that all the foreground processes will run, otherwise you can't move it.

This process has a service bound to the visible activity.

A process is not within either of these two, but it runs a service that is started by StartService ().

Although a service process does not directly affect what the user sees, they usually do things that the user cares about (such as playing music or downloading data), so the system will not kill it if the foreground process and the visible process cannot survive.

4. Background process

A process has an activity that is currently not visible (the OnStop () method of the activity is called).

Such processes do not directly affect the user experience, so the system can kill them at any time to provide storage space for the foreground, visible, and service processes. There are usually a lot of background processes running. They are stored in an LRU (least recently used) list to ensure that the process that owns the activity that was recently seen is finally killed. If an activity correctly implements its life cycle method and saves its current state, the process that kills it will not affect the user's visual experience. Because when the user returns to the activity, the activity restores all of its visible state.

5. Empty process

A process does not have an active component in it.

The only reason to keep this type of process is the cache, which can increase the speed at which the next component will run. Systems often kill them in order to balance the overall system resources between the process cache and the underlying kernel cache.

Process level in Android

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.