In-depth knowledge and basic concepts of Android system

In-depth knowledge and basic concepts of Android system

The basic components of Android applications include Activities, Services, Broadcast receivers, and Content providers. Before discussing these components and the Android operating system in depth, the author proposes to first understand the operating behavior of Android users.

List of applications on your Android phone and basic operations related to the applications. Users can tap the app icon to open the app, and can also use the icons in the navigation bar to navigate between Back, Home, and Recent Apps.

Technical aspects of the Android operating system

The Android operating system is actually a customized version of Linux. Just like creating different users in Linux, each application is actually a user. Each application has its own private area, which can be accessed through permissions. Every installed application has a UID (User ID) and GID (Group ID):

  • UID: Control application access to files, folders, resources, etc.
  • GID: Allows a specific group of users to be grouped together, and users in the group can access shared files within permissions.

Next, the article introduces the role of four basic components:

  1. Activity : The basic building block of an Android application, taking up all the space it takes up and can be stacked on top of each other.

  2. Services : Background process that activates a service when another service is needed. Services can be provided to components outside the application, thus making some basic functionality of the application available to other applications.

  3. Broadcast Receivers : Similar to interrupt handlers, triggered when important events occur for processing in the application. Inactive when not handling specific events.

  4. Content Providers : Used when you want to access data from another application. It can retrieve files or other storage components, often relying on SQLite.

Finally, AndroidManifest.xml defines the basic components used statically in the application and explains that the Android operating system checks the manifest when starting the application and opens the necessary applications as needed. When a user opens an Android phone, the system displays an Activity containing an application icon, and the application can be accessed through various basic components (such as clicking on the application icon, notifications, etc.). An application has as many entry points as there are components.

The above figure shows the response process of the Android system when the user clicks the application icon. After the user clicks the application icon, the system will call the method in the launcher to onClick()respond. Then, Activity Manager calls startActivity()the method. Under the Android operating system, Activity Manager calls startViaZygote()methods. Next, Zygote (the child process incubator) forks the application to launch it and pass it to the system.

Activity Manager

  1. Activity Manager is responsible for managing basic components. In application development, if an ANR (Application Not Responding) error occurs, it is usually caused by Activity Manager. In addition, Activity Manager also handles Activity life cycle, OOM (out of memory) and low memory conditions.

  2. When the user clicks on the app, the app may already exist in the back stack or it may be launched for the first time. Applications launched for the first time begin to manage more system resources.

  3. The hardware has a certain capacity and this process cannot proceed indefinitely. The system needs to terminate or release old applications or low priority applications when starting new components/applications. To prevent users from detecting the termination of these processes, Android provides lifecycles for components. LifeCycle CallBacksThe system manages the status of these components through life cycle callbacks ( ).

To sum up, this content describes the operation process after the user clicks the application icon in the Android system, and the key role of Activity Manager in processing applications and components.

Android memory management

Memory management in Android includes two structures: Out Of Memory (OOM) and Low Memory.

  1. OOM memory management: OOM is actually the same as OOM in Linux. It creates a scoring system from -17 to +15 to clean up memory. The higher the score, the greater the possibility of being terminated by OOM. The score is calculated based on parameters such as CPU time, running time, memory size, etc. OOM comes into play when memory starts to fill up.

  2. Low Memory Memory Management: Android developers wanted to have better control over memory, so they created the Low Memory structure. In Low Memory, the system triggers when a certain threshold is reached. The system saves running background processes. As the thresholds increase, OOM kills non-critical background processes as well as foreground applications held under these thresholds.

To sum up, this paragraph illustrates the two structures of Android memory management: OOM and Low Memory. OOM terminates processes based on a scoring system, while Low Memory triggers when a threshold is reached and saves running background processes for better memory control.

Zygote

Zygote is a dedicated structure in Android, its functions and working principles:

  1. Zygote is a specialized structure for launching applications : Zygote brings together components shared by all applications to unify them and shorten their launch process. It is active only when a new application needs to be launched and prepares resources that the application may need while running.

  2. Zygote creates a socket in the system : when it receives an application launch request, Zygote listens and forks the operation. The benefit of forking is that all resources the application may need are available and preloaded. Forked operations actually use their own copy, so a single copy of the resource remains in RAM regardless of the number of applications.

  3. The first thing Zygote starts is System Server : it runs as a separate process.

Additionally, the article mentions that Jetpack Compose is a special case. Since Jetpack Compose is a standalone library, it cannot benefit from Zygote. Therefore, it uses Profile Installers starting from version 1.0.

Intent

The role and importance of Intent in Android:

  1. Intents allow components/applications to interact : an Intent is a passive object and its effects may vary depending on its content, the mechanism used and the installed applications. If the application itself cannot fulfill the user's request, it can provide functionality that meets the user's needs by interacting with other applications. For example, in a camera-album operation, the operation can be performed by interacting with the application provided by the system.

  2. The navigation bar provided by the system also uses Intent : The navigation bar provided by the system actually calls Intent to implement functions such as return, home screen, and recently used applications. For example, the home screen button uses Intent.CATEGORY_HOME to implement the home screen functionality.

In summary, Intent is an important mechanism in Android for interaction between components and applications. It allows applications to meet user needs by interacting with other applications, and is used by components such as the system navigation bar to trigger different operations. .

Guess you like

Origin blog.csdn.net/u011897062/article/details/132921141