“This is the first day of my participation in the First Challenge 2022. For details: First Challenge 2022.”
The Activity creation process
The main process
- [To Know]
- MInstrumentation: The ability to trace the application and activity lifecycle
- AMS is an Activity Manager Service that records and manages the status of activities and other components in the system through ActivityStack and other data structures, and provides query functions.
We usually start an Activity either by clicking on the icon or by using startActivity in an Activity. When started with startActivity:
Intent intent = new Intent(this,MainActivity2.class);
startActivity(intent);
Copy the code
This is just a superficial API call, it’s actually the mInstrumentation that creates the activity, but the mInstrumentation is still more of a call on the upper level, at the mInstrumentation level it’s more about detecting the condition on which the activity was created, The mInstrumentation hands the final generated task to AMS, but AMS runs on the system_server process, where cross-process communication is involved, So AMS is called in the app process via the mremote of ActivityManagerNative, which is the remote proxy of AMS
System_server process
As mentioned earlier, AMS uses ActivityStack and its data structure to record and manage activities in the system. Therefore, when tasks are passed to AMS, ActivityStack detection and recording must be involved
- [To Know]
- ActivityStack is a management class that manages the various states of all activities in the system and maintains a list of TaskRecords internally
- ActivityStackSupervisor management ActivityStack
The relationship between
In this process, the main activity of the creation of related parameters for some processing, as well as the activity of the record. When this is done, AMS passes the work back to the main process, which is called by the proxy object IApplicationThread
Thread is actually IApplicationThread, a proxy object for the main process
The main process
When the task is returned to the main process, it is handed off to a specific thread through a handler
Create an activity through the class loader
And try to create the application when, for example, the application will not be created if it already exists
The activity also has a final attach process, which is related to the subsequent creation of the View