AMS is often talked about in interviews, do you really understand it?

During interviews, these questions are often asked:

  • Do you understand the startup process of Activity?
  • What role does AMS play in Android, and a simple analysis of the source code of Android
  • Why should system_server be started in Zygote instead of being started directly by init?
  • Why use the Zygote process to incubate the application process instead of letting the system_server incubate?
  • Can you tell me exactly what caused the deadlock?
  • Why doesn't Zygote use Binder mechanism for IPC communication?

Whenever this time, ten thousand grass mud horses are galloping past...

Most Android developers are directly confused when they encounter this kind of interview question. Many people have read the relevant answers, but they have only scratched the surface and have not grasped the principles in depth. Naturally, they will be caught off guard during the interview. .

The following picture must have been seen by everyone. Google officially provided a classic four-layer architecture diagram, which is divided into from bottom to top: Linux kernel, system library and Android runtime environment, framework layer, and application layer. Each layer contains a large number of sub-modules or subsystems.

The Android system startup process is a process from bottom to top:

Loader → Kernel → Native → Framework → App

Among them, AMS (ActivityManagerService) is a particularly important system service in the Android system, and it is also one of the system services that deal with the most upper-level APP (almost all APP applications need to deal with AMS), the startup of the four major components, each life cycle Method calls basically need to be processed through it, so it involves a lot of knowledge points. To understand the inner workings of Android, one must first understand how AMS works .

For example, in the startup process of Activity, AMS is the component management and scheduling center, which does nothing but manages everything! AMS is ubiquitous in the complete process of the Android system from booting to the desktop and then to APP startup...

When we have a deep understanding of the Android startup process and AMS features, we can solve many problems in project development, such as: screen adaptation, custom View and ViewGroup, APK reinforcement, thermal repair, component routing, skin replacement, plug-in , leakCanary memory problem analysis, Hilt injection, Jetpack principle, Glide principle, RXJava principle, launch_mode, permission verification, four major components and other related logic and code... But AMS itself is complicated and difficult to understand, and many Android developers who have worked for many years also It's hard to figure out what AMS does. At the same time, the overall operation process of the system has become the hardest hit area for interviews with major manufacturers. The figure below shows the complete main line process of the mobile phone from booting to running the desktop, and then clicking the icon on the desktop to run the APP.

If you haven't mastered the Framework yet, and want to get a thorough understanding of it in the shortest time, you can refer to "Android Framework Core Knowledge Points" , which includes: Init, Zygote, SystemServer, Binder, Handler, AMS, PMS, Launcher... ... and other knowledge point records.

"Android Framework Study Manual":https://qr18.cn/AQpN4J

  1. Boot Init process
  2. Start the Zygote process at boot
  3. Start the SystemServer process at boot
  4. Binder driver
  5. AMS startup process
  6. The startup process of the PMS
  7. Launcher's startup process
  8. The four major components of Android
  9. Android system service - distribution process of Input event
  10. Android underlying rendering-screen refresh mechanism source code analysis
  11. Android source code analysis in practice

Guess you like

Origin blog.csdn.net/weixin_61845324/article/details/132031627