Send a request to start the Activity

Click on the icon on the desktop, and in the application launcher, call the startActivity method of the Context. The implementation of the Context is in the ContextImpl, and as you can see from this implementation class, Start the Activity with Instrumentation. In Instrumentation, through the way of communication between Binder processes, to obtain the Binder object of AMS, through the Binder object, to INITIATE the activity request to AMS.

AMS handles requests

AMS calls the PMS to verify the parameters of the Activity to be started, such as parsing incoming intent information, the validity of the Activity, the startup mode, etc., as well as processing the stack information of the Activity. Once the parse is complete, cause the Activity at the top of the stack to perform onPause and then officially start the Activity.

Create process (if the application is not created)

If the application is not started, the process of creating the application needs to be performed by ams, in the form of sockets, to tell Zygote to fork out a new child process, using sockets instead of binder. The created child executes activityThread. main, which is the entry point to the application and performs various initialization operations, including Application, Handler, looper, etc.

Actually start the Activity

Then you actually start the activity. AMS sends notifications to our application to start the Activity through its Binder references, called ApplicationThread objects. Because messages are received through the Binder communication, they need to be switched from the Binder thread to the UI thread through the message mechanism of the Handler.

The main process that starts is the life cycle of the Activity. When executing the life cycle of the Activity, the Fragment controller notifies you of the change in the life cycle of the Activity. Versions 9.0 and later use the state machine design mode to manage the Activity lifecycle.

reference

Android Relearn Series of activities to start the process (1)