How the Android app works-Live cat learn Android development

Source: Internet
Author: User

how the Android app works
Android is based on the Liunx kernel, but unlike traditional liunx-based PC systems,The user has no absolute control over the Android app. PC System,selecting "Exit" or "close" option on the application's system menu will kill the process directly. This is not the case with Android systems. instead, the system frees the resources of the application when the system needs to free up memory to run a new process or to ensure that some background and front-end processes execute smoothly, and this release process has a level of importance, followed by a description of the live cat:

the hierarchy of processes in Android is as follows (high-to-low importance):
1, the front-end process. As the name implies, the front-end process is currently displayed on the screen and user interaction process, the number of front-end processes in the system, and this process is the most impact on the user experience, only the system's memory is scarce enough to maintain and the user's basic interaction when the front-end process is destroyed. This process is therefore of the highest importance.
2, visible process. Visible process also has a visual interface, but currently not the topmost interface (the topmost interface in the front-end process), the visible process calls OnPause (), visible process is less important than the front-end process, but the interaction is still very large, because the user may switch over at any time, So the system won't easily destroy it.
3, the service process. A service process, which calls the StartService (), is the daemon that is said in Unix, is not visible to the user, but ensures that some important events are monitored or maintained in certain States, such as network data transmission, background music playback, Such processes are not sufficient and are destroyed in order to ensure the smooth running of the front-end interaction.
4, the background process. This is called the background process may be confused with the general sense of the background process, to show that the background process in Android is called OnStop (), can be understood as the user does not have a desire to interact with the process, so the background process here is a bit "to destroy" meaning.
5, empty process. This is a system caching mechanism, is actually a process shell, when a new process is created, this empty process can speed up the process creation, when the system memory is low, first destroy the empty process.
process importance levels in Android

Next, combine the life cycle of Android activity to illustrate:




when a process is created, the system creates an activity (active), followed by calls to OnCreate (), OnCreate (), mainly to do some initialization, such as reading the XML resource file creation layout, setting the main interface of various listening functions, etc. Each process will call OnCreate ().


Next is OnStart (), it should be stated that in the default activity (that is, the program starts the activity entity we see), the programmer does not need to write the code explicitly to call OnStart (), the system will silently help you call; When you need to create all new activity in this program except for the default activity, you must explicitly call this OnStart (), this onStart () has a new name called startactivity (intent), The intent here represents an intention, which is the new activity we want to create.
Then there is Onresume (), which calls Onresume () when we jump from the main program interface to another place and then jump back. And then the program ran, and we called him process a, and if the other process becomes the front-end process (process B), then process a will call OnPause (), which will save the state of the process for data persistence. In two cases, process a again becomes the front-end process, and process a calls Onresume () to resume operation, and if the system is running out of memory during process a at OnPause (), process a may be destroyed to free up memory for other processes (why is it possible to be destroyed?). See above for the Android process importance level description), if the user switches to process a again, this is the system just re-create a process, it is no longer process a (because process a has been destroyed at this time).


when OnPause () is called and the user presses the return key (back), process a calls onStop (), which says that the user has no desire to interact with process A at this time, so that process a becomes the object to be destroyed (why is it not destroyed directly?). The answer is also explained in the importance level of the Android process). So if the user switches to process a again when a process A has not been destroyed, process a becomes the front-end process, and process a calls Onrestart () and calls OnStart () to start the process again (at this point, the process a itself is not replaced by another, Because process A has not been destroyed), it can be understood here to "wake up" process a. If unfortunately, the system memory is not enough, the call of OnStop () after the process a may be destroyed again, as pictured on the picture, here no longer repeat. The OnDestroy () call behind OnStop () is called by the system to destroy processes and free memory when the system is low on memory.

How the Android app works-Live cat learn Android development

Related Article

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.