Activity Start flow
process
We don’t need to get too detailed, just focus on the main flow and a few key points.
The main process is: suspend the original Activity-> check whether the process is started, start the process -> Start the Activity
- Pausing the original Activity: Pausing the Activity with PasueActivityItem
- Start processes: Zygote. process, which creates ActivityThreads and Instrumentation
- Start the Activity with the LaunchActivityItem. This process creates the PhoneWindow and DecorView and sets the theme
StartActivity - > after Instrumentation \ ActivityTaskManagerService \ ActivityStack \ ActivityStackSupervisor - > PauseActivityItem -> Start the process (zygote.process) -> LaunchActivityItemCopy the code
Phase,
Create Process
As you can see in the code below, ActivityThread and Instrumentation only have one per process.
* ActivityTaskManagerService.startProcessAsync
* ProcessList.startProcess
* ZygoteProcess.start
* ActivityThread.main() -> Looper.get -> new ActivityThread -> activityThread.attach -> new Instrumentation -> looper.loop
Copy the code
LaunchActivityItem
Here is the core code to start the Activity. Before executing the code change, it is a series of judgment + calls from App side to service side. Service and through layer upon layer calls eventually transferred to the ActivityStackSupervisor. RealStartActivityLocked.
* ActivityTaskManagerService.getLifeCycleManager.scheduleTransaction
* ClientLifeCycleManager.scheduleTransaction
* ApplicationThread.scheduleTransaction
* ActivityThread.scheduleTransaction
* ClientTransactionHandler.scheduleTransaction -> sendMessage
* ActivityThread.H.EXECUTE_TRANSACTION
* LaunchActivityItem.execute
* ActivityThread.handleLaunchActivity
* ActivityThread.performLaunchActivity -> Instrumentation.newActivity -> r.packageInfo.makeApplication() -> activity.attach -> new PhoneWindow -> get DecorView
* Activity.setTheme
* Instrumentation.callActivityOnCreate
Copy the code
PauseActivityItem
* ActivityTaskManagerService.getLifeCycleManager.scheduleTransaction
* ClientLifeCycleManager.scheduleTransaction
* ApplicationThread.scheduleTransaction
* ActivityThread.scheduleTransaction
* ClientTransactionHandler.scheduleTransaction -> sendMessage
* ActivityThread.H.EXECUTE_TRANSACTION
* PauseActivityItem.execute
* ActivityThread.handlePauseActivity
* ActivityThread.performPauseActivity
* Instrumentation.callActivityOnPause
Copy the code