Android Application lifecycle (finish)

Source: Internet
Author: User

Thank you !!!

Reprinted Please note: http://blog.csdn.net/richway2010/archive/2011/06/29/6574987.aspx

[Bloggers: Dear bloggers, netizens, and everyone else! Welcome to this blog. You are welcome to have more exchanges, give more comments, learn from each other, and make mutual progress. Our slogan is: study hard and make progress every day .]

What is the lifecycle of the next Android Application? In order to provide a solid foundation for subsequent development.

The so-called application life cycle is nothing more than the whole process from application process creation to extinction. However, all of them have their own special characteristics. Indeed, the end of the lifecycle of an android application is not executed by the application process, but depends on the Android system, that is, the android application is born and died by "day ", you cannot control your own destiny. This may be related to some programs in our traditional programming thinking. For example, the C language program that was originally learned finally received the internal or external exit request and the running process exited from the main function through return, rather than directly killing by the system, this is rare. So why are Android designers so designed? What are the benefits of this design?

In fact, most mainstream smartphones are multi-tasking. I often use my own mobile phones to play music while playing music, and may also drive ucweb and QQ. This truly gives users an unparalleled experience. However, one problem that cannot be ignored is that there is only so much memory on the mobile phone. As the number of applications opened increases, it may be that the response time of the application is too long or the system is suspended. Therefore, if the life cycle of the Android Application is handed over to the system for processing, the android system is responsible for car maintenance when the system memory is insufficient, choose to abort important applications to reclaim memory for more important applications.

So what is the importance standard for the system to stop Android applications? In Android, all processes are divided from high to low by importance based on the application components and the current running status of the components, as shown in:

1. Foreground Process
As the name suggests, a foreground process is an activity process that is displayed at the front of the screen and interacts with the user, or a broadcastreceiver of the process is running. This process is of the highest importance, and there are only a few such processes in the system. The system does not stop the foreground process unless the system memory is very low and never stops.
Generally, one of the following conditions can be considered as a foreground process.
1) The process is running an activity that interacts with the user at the frontend (its onresume () method will be called)
2) The process has a running broadcastreceiver (its broadcastrecevicer. onreceive () method is being executed)
3) A process has a service and code is being executed in a callback function of the service.
2. Visible Process
Visible processes are processes that are visible to users but not displayed on the screen. It can be seen that the process is also very important, usually not terminated by the system, unless in the case of car maintenance Shuai, in order to maintain the normal operation of all the front-end processes and have to stop the visible process.
Generally, a visible process can be considered if one of the following conditions is met.
1) there is a non-foreground activity that is still visible to the user (the onpause () method is called ). For example, the current foreground activity is a dialog box, and the previous activity is still visible.
2) A service bound to a visible activity
3. Service Process
A service process is a process with a service and started using the startservice () method. These processes are usually run in the background and invisible to users. However, the work done by these processes is also important, such as playing music in the background. Therefore, unless the first two high-level processes can work normally, the system generally does not stop the service process.
4. background processes
Background processes run activity that is invisible to users (the onstop () method has been called). These processes have no direct impact on user experience. When the above processes require memory resources, recycle from the background process. Generally, many invisible processes are running in the LRU (least last used) list, so that when the memory is insufficient, they will be recycled immediately. When a process needs to be aborted, the system will ensure that the last process viewed by the last user is aborted.
5. Empty Process
There are no application components in a blank process, and the only reason for such a process is to provide a cache mechanism to shorten the time required for the next startup of the application. The system regularly suspends empty processes to balance the program cache and system cache.

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.