Activity start related source code is more complex, involving more links, I often in a clear after a period of time to read and read for the first time, still have to spend some time to clarify. In order to deepen the understanding of the Activity startup process and facilitate future review, I summarized the entire Activity startup process into a diagram. This figure is based on 9.0 Android source code (Activty related code is constantly reconstructing but the core logic is still unchanged).
The role of the relevant modules in the figure
ActivityThread
It can be thought of as the mainline class for an application to run. Its main functions are:
Contains the entry to the application: main()
This function does the following:
- using
ApplicationThread
Established the application withAMS
The link. - constructed
Instrumentation
. - Created the application
Application
. - Turns on the message processing model for the main thread.
Manages the operation of four application components
ApplicationThread
It is the application’s Binder object in AMS that AMS uses to communicate with the ActivityThread and the four component related callbacks to the ActivityThread.
Instrumentation
This class comes with ActivityThreads and is used to help activityThreads manage Activity related work. It holds the Binder of AMS on the application side, through which ActivityThread communicates with AMS.
ActivityManagerService
As the core service of Android, it mainly manages the operation of the four major components of Android system.
ActivityStackSupervisor
Manage all Activity stacks. MHomeStack, mFocusedStack and mLastFocusedStack are internally managed. MHomeStack manages the Launcher related Activity stack. MFocusedStack manages the Activity stack currently displayed in the foreground Activity; MLastFocusedStack manages the Activity stack from which the Activity was last displayed in the foreground.
ClientLifecycleManager
Helps AMS call back to the four major component life-cycle related methods of an application.
Refer to the article
(Android 9.0) Activity start process source code analysis
The End
Welcome to mineAndroid Advanced PlansSee more dry goods
Welcome to follow my wechat official account: Susion Heart