Transferred from: http://www.ibm.com/developerworks/cn/opensource/os-cn-android-mmry-rcycl/index.html
The execution environment for Android apps
Android is a Linux-based kernel for mobile terminal operating systems.
To adapt to its special needs as a mobile platform operating system. Google has made a special design and optimization, making its process scheduling and resource management and other platforms of Linux have a significant difference. The main areas include the following levels:
Application Framework
The application Framework separates the entire operating system into two parts. As an application developer, all apps are executed on top of the application Framework. There is no need to care about the bottom of the system. The application Framework layer provides a rich application programming interface for application developers. such as Activity manager,content provider,notification Manager. As well as various forms Widget resources. At the application Framework level, Activity is the most important part of an APP. Typically each activity corresponds to a view (or one screen) on the screen, and an APP can have one or more activity. The application is packaged into an. apk format file that is interpreted by the Dalvik VM for execution.
Dalvik VMS
The Dalvik virtual machine uses a register schema instead of the JVM's stack structure. The. class file compiled by the Java program does not interpret execution in Dalvik. So Google provides a DX tool for converting. class files into the. dex format that DALIVK can recognize.
Detailed Dalvik VM details are not the focus of this article and are not discussed below.
Linux kernel
As mentioned above, all apps are written in Java code and interpreted in the Dalvik VM. In the Android operating system, each Dalvik VM has a Instance corresponding to a process in the Linux kernel. You can use the ADB shell tool to view the current process in the system.
For example, as seen in the. Android2.3.3 the list of processes in the kernel after startup.
Each entry that the UID identifies as APP_XX is a process occupied by an app, and the Android design allows each application to be interpreted by a separate Dalvik instance, and each Linux kernel process loads a Dalvik instance. In this way, the app's execution environment is provided. In this way, each APP's resources are completely shielded from each other.
Despite the difficulty of introducing interprocess communication at the same time, it also brings more security.
Android Memory Recycling Principle
The following will analyze the Android operating system resource management mechanism from the application Framework and Linux kernel two levels.
The reason why Android uses a special resource management mechanism is that it is designed to target mobile terminals, all available memory is limited to system RAM, and the corresponding optimization scheme must be designed for such limitations. When the Android app exits. Does not clean up its occupied memory, the Linux kernel process also continues to exist, so-called "quit without shutting down."
This allows the user to get a response at the first time when invoking the program. When system memory is low, the system activates the memory reclamation process.
To ensure that the user experience is not affected by memory reclamation (such as killing the current active process), Android enforces the default five recycling priorities based on the components and their status that are executed in the process:
IMPORTANCE_FOREGROUND:IMPORTANCE_VISIBLE:IMPORTANCE_SERVICE:IMPORTANCE_BACKGROUND
Memory recovery mechanism for Android operating system