Understand the process of creating an Android process Understand the process of starting an Android process
Stand on the shoulders of GITYUAN and use a god diagram to show the basic startup process.
Figure above also need to check the source code, a brief introduction to the startup process
In the overall description of Android system, Zygote incubates the first process is system_server process, and incubates the first App process is Launcher, that is, desktop App.
When you click on the desktop App, the Launcher process is the process in which the Launcher is located, and the remote process is started with the Binder to send messages to the system_server process.
N services, such as ActiivityManagerService and WindowManagerService, are started in the system_server process. Starting the Process of operation will call AMS. StartProcessLocked method, internal call Process. The start (android. App. ActivityThread); The Zygote process is then told to fork the child process, i.e. the APP process, through socket communication. After the process is created, load the ActivityThread into the process and execute the activityThread.main () method.
In the app process, the main method instantiates the ActivityThread, creates ApplicationThread, Looper, and Hander objects, calls attach for communication, and Looper starts the loop. The Attach method obtains the ActivityManagerProxy object, which implements the IActivityManager interface. The attach method invoks attachApplication(mAppThread) as a client and informs AMS of the thread information.
In the process of system_server, AMS will call ActivityManagerNative. OnTransact method, the real logic on the server AMS. AttachApplication method, Internal call AMS. AttachApplicationLocked method, the method of parameter is IApplicationThread, In this case, the ApplicationThreadProxy object is used to communicate with the ApplicationThread object in the Process created earlier through process.start (). AttachApplicationLocked method can deal with the Provider, the Activity, Service, Broadcast related process, called ApplicationThreadProxy. BindApplication method, Through Binder communication, passed to ApplicationThreadNative. OnTransact method.
In the process of app, the real logic in ActivityThread. BindApplication method. The main function of the bindApplication method is to send the message H.set_core_settings and h.bin_application to the main thread in sequence. Then create the Application,Context, etc. The Activity’s callbacks also communicate with the Binder and send different message processing. .