1, start the process click icon occurs in the application process Launcher, startActivity() function is finally by Instrumentation through Android’s Binder cross-process communication mechanism to send messages to the system_server process; In system_server, ActivityManagerService tells Zygote to fork a child (app) via socket communication to start a process

2. Start the main thread

Once the app process starts, instantiate the ActivityThread and execute its main() function: Create ApplicationThread, Looper, Handler and open the main thread message loop looper.loop ().

3. Create and initialize the Application and Activity

The Main () of the ActivityThread calls the ActivityThread# Attach (false) method for Binder communication, Inform the system_server process to execute ActivityManagerService#attachApplication(mAppThread) to initialize the Application and Activity.

ActivityManagerService#attachApplication(mAppThread) initializes the Application and Activity in the system_server process, with two key functions:

The -thread #bindApplication() method tells the main thread Handler to create the Application object, bind the Context, and execute the Application#onCreate() lifecycle

ActivityThread#ApplicationThread#scheduleLaunchActivity() is called in the mstackor# attachApplicationLocked() method. The main thread Handler message notifies the Activity object to be created and then calls mInstrumentation#callActivityOnCreate() to execute the Activity#onCreate() lifecycle

4. Layout & drawing