The Android process life cycle of Process Lifecycle

 

The Android process life cycle of Process Lifecycle


The process life cycle

  The Android system will try to keep the application process, but sometimes in order to give the new process and the more important process recycling some memory space, it will remove some of the old process.

  In order to determine which processes leave, which process is killed in the process, the system according to the component and operation state, is assigned a priority level for each process.

  The lowest priority process was first kill.

  Hierarchical structure of the significance of five grade , here are the five processes, in order of importance arrangement, the most important on the front.


A foreground process Foreground process.

  The foreground process is required for the user to do process, if meet one of the following circumstances, a process is considered to be in the foreground:

  1 the process holding a user interaction with the Activity (Activity) is in the onResume (state).

  2 process held a Service, Activity to bind the Service and the user is interaction.

  3 the process holding an Service, the Service is running in the foreground, which it calls the startForeground().

  4 the process holding an Service, the Service is executing its lifecycle callback function(onCreate(), onStart(), or onDestroy()).

  5 the process holding an BroadcastReceiver, the BroadcastReceiver is executing its   onReceive (  method);.

  Kill the foreground process requires user interaction, because the process priority is the highest.

 

Two visible Visible process process.

  If the components of a process does not contain any front desk, but still affects the user can see on the screen content, is the visible process.

  A visible process meets one of the following circumstances:

  1 the process holding an Activity, the Activity is not in the foreground, but is still visible to the user (in onPause) ( call and no call onStop () state).

  This happens in, for example, the activity opens a dialog box, so that the activity would later in the visible.

  2 the process holding an Service, the Service and a visible (or front) Activity binding.

  Visible processes is also considered to be very important, generally will not be destroyed, unless it is in order to ensure that all the foreground process operation and had to kill the visible process.


Three. The service process of Service process

  If a process running in a service, the service is through the   startService ( ); open, and do not belong to the above two kinds of higher priority, this process is a service process.

  Although things bind service process did not and the user can see, but usually they are doing is of interest to the user, such as background music, background download data.


Four. The Background background process process

  If the process does not belong to the above three kinds of circumstances, but the process is holding a invisible to the user activity (activity) onStop ( is called onDestroy (), but no call state), that the process is a background processes.

  The background process does not directly influence the user experience, the system to the foreground process, visible process, service process and arbitrary killing background processes.

  Usually there are many background processes, they will be stored in a LRU (least recently used) list, so that you can ensure that the user has recently used activity was finally destroyed, that is the first time the farthest activity destruction.


Five free process.

  If a process does not contain any active application components, that is empty process.

  The only reason to keep this kind of process is to cache needs, in order to speed up the next component to start the process of start time.

  In order to balance process caches and the underlying kernel cache resources, often will kill the empty process.


Instructions

  1.Android will put on a high priority process as much as possible.

  For example, a process has a visible state of activity and a service, this process could be considered a visible process, not a service process.

  2 a course rating may be because rely on other processes and improve service, a process to another process, process priority it priority than its service is low.

  For example, a content provider A in the process of providing services to a B in the process of the customer, a service or A in the process of being bound to a component in a B process, A process priority at least and B process priority as high.

  3 because the service process priority than the background process high priority, so for a need to start a long time operation of the activity, open a service is better than the method to create a worker thread, especially for the operation will probably exceed activity duration at.

  For example, to upload an image file, should open a service to upload work, such work in the user leaves the activity is still in progress. Using the service will guarantee the operation of at least the service process priority.


Reference material

  Sandy Zhang Android explain profound theories in simple language video tutorial — — process life cycle.

  API Guides: Processes and Threads

  http://developer.android.com/guide/components/processes-and-threads.html

 

 

Posted by Clark at November 17, 2013 - 4:44 AM