1. startup process/system/rootdir/init. RC
Zygote
/Framework/base/cmds/app_process/app_process.cpp
/Framework/base/CORE/JNI/androidruntime. cpp
Start
Startvm sets the heapsize at startup, default 16 mstartrreg
App_process
Main () create a androidruntime first, then androidruntime. Start ("com. Android. Internal. OS. zygoteinit"), create the zygote.
Zygoteinit
Main ()
1. register the IPC socket.
2. preload classes
3. startsystemserver
4. runselectloopmode
Systemserver start a serverthread, In the serverthread, create the Java World, AMS, WMS, PMS and so on.
1. When the system starts, the INIT process will create the zygote process. The zygote process will be responsible for creating and starting other processes at the framework layer of the android application.
2. the zygote process will first create a systemserver process, which is responsible for starting key services of the system, such as packagemanagerservice and activitymanagerservice.
3. When we need to start an Android Application, activitymanagerservice will notify the zygote process to create a new process for the application through the socket inter-process communication mechanism.
2. A new activity start
AMS: startprocesslocked
Process. Start ()
The process will write some strings to zygote socket, The runselectloopmode then call zygoteconnection: runonce () to fork a new process, then call runtimeinit: zygoteinit to establish the binder communication mechanism and call
The child process 'main ().
AMS in systemserver's process, so the mechanism is SS send string message to zygote, then zygote fork a new child process and call it's main ().
1. Step 1-Step 11: launcher notifies activitymanagerservice through the binder inter-process communication mechanism. It wants to start an activity;
2. Step 12-Step 16: activitymanagerservice notifies launcher to enter the paused state through the binder inter-process communication mechanism;
III. step 17-Step 24: launcher notifies activitymanagerservice through the binder inter-process communication mechanism. It is ready to enter the paused state, so activitymanagerservice creates a new process to start an activitythread instance, the activity to be started is run in the activitythread instance;
4. Step 25-Step 27: activitythread transmits an applicationthread-Type binder object to activitymanagerservice through the binder inter-process communication mechanism, so that activitymanagerservice can communicate with it through this binder object in the future;
5. Step 28-step 35: activitymanagerservice notifies activitythread through the inter-process communication mechanism of the binder. Now everything is ready, and it can actually start the activity.
Activitythread-> receivmlaunchactivity