The life cycle of Android apps

Source: Internet
Author: User

The so-called application lifecycle is nothing more than the entire process of application processes from creation to extinction. However, all of this is carried out alone, of course, it has its particularity. Indeed, the end of the life cycle of an Android application is not performed by the application process itself, but depends on the Android system, the Android application that lives and dies by "Heaven" and cannot dominate its own destiny. This is with our traditional programming thinking may have procedures, such as the original C language program is the last to receive internal or external exit request and running process from the main function through the return exit, rather than the system directly kill, this is rare. So why are Android designers so designed? What are the benefits of this design?

In fact, most of the mainstream smartphones are multi-tasking, I often use their own mobile phone while listening to music and may also open UCWeb and QQ, it is true that this brings users experience is unparalleled. However, one problem that can not be overlooked is that there is only so much memory in the phone, and as the number of applications we open increases, it may be that the application responds too long or the system is in a bad state of suspended animation. Therefore, if the Android application life cycle is referred to the system, then in the case of low system memory, the Android system Shere, selectively to abort some of the more important applications, in order to reclaim memory for more critical applications to use.

So, how does the system abort the Android application based on a standard of importance? In fact, in Android, all processes are divided into five degrees of importance from high to low, depending on the component of the application and the current running state of the component, as shown in:

² foreground Process

As the name implies, the foreground process is the activity process that is displayed at the front of the screen and interacts with the user or a broadcastreceiver of the process is running. Such processes are of the highest importance and there are only a few such processes in the system. The system does not choose to abort the foreground process unless the system memory is very low and is aborted in case of a last resort.

Generally, one of the following conditions can be considered a foreground process

1) The process is running at the forefront of an activity with user interaction (whose Onresume () method will be called)

2) The process has a running Broadcastreceiver (its broadcastrecevicer.onreceive () method is being executed)

3) The process has a service, and there is code executing within a callback function of the service

² Visible Process

Visible processes are those that are visible to the user, but do not appear in the most front-end of the screen. The visible process is also very important and is usually not aborted by the system, except in the case of Shere, which has to abort the visible process in order to maintain the normal operation of all foreground processes.

Generally, one of the following conditions can be considered a visible process

1) There is a non-foreground but still visible activity for the user (the OnPause () method is called). For example, the activity of the current foreground is a dialog box, and the last activity is visible

2) with a service bound to the visible activity

² Service Process

A service process is a process that has service, which is initiated by the StartService () method, which is typically run in the background and is not visible to the user. However, the work done by these processes is also more important, such as the work of playing music in the background. Therefore, the system generally does not abort the service process unless the first two high-level processes are guaranteed to work correctly.

² Background Process

The background process runs an activity that is invisible to the user (called the OnStop () method), which has no direct impact on the user experience and can be recycled from the background process when the process requires memory resources. In general, there are a lot of invisible processes running in the system, which are stored in the LRU (least last used) list so that when the memory is low, it is recycled at the first time. When the process needs to be aborted, the system will ensure that the last one seen by the user is aborted.

² Empty Process

There are no application components in an empty process, and the only reason for this process to exist is to provide a caching mechanism that shortens the time required for the application to start the next time. The system will frequently abort the empty process, thus achieving the balance between the tuning program cache and the system cache.

Http://www.cnblogs.com/royenhome/archive/2010/04/25/1719854.html

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.