Briefly describe the startup process of the application

1. The first process that the android system starts is init.

 

2.init will fork a process called zygote. (All application processes are forked by zygote)

   The zygote process is actually a process on the jvm, which starts the jvm, opens the listening port (registerZygoteSocket), and preloads classes and resources.

 

3. During the startup process of zygote, a system_server will be forked. Because it is a fully replicated zygote, it is necessary to close some things that have been running so far, such as listening ports.

 

4. Services such as ActivityManagerService will be started in system_server to listen for requests to create activities.

 

5. When ActivityManagerService receives a request to start an activity, first check if there is a corresponding registered process, if not, notify zygote, let it fork a process, and then register. If so, send a message directly to notify the process to start the activity.

 

Why bother so hard? The main thing is that it is fast. Android is a java program, and each process is a jvm. When starting, it needs to initialize and load many classes, and this part is repeated. Of course, recreating is not as fast as copying. In addition, fork on linux follows copy-on-write, so you can still share many resources of the parent process.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326926847&siteId=291194637