activity啟動流程速記筆記
Activity.startActivity(Intent intent)----Activity.startActivityForResult(Intent intent)----Instrumentation.execStartActivity()----ActivityManagerNative.getDefault().startActivity
----ActivityManagerService----Binder----IActivityManager----ActivityManagerProxy----ActivityManagerService.startActivity
----ActivityManagerService.
startActivityAsUser設定了userId-----ActivityStackSuperviso.startActivityMayWait主要進行了Intent的檢查----ActivityStackSuperviso.startActivityLocked生成ActivityRecord-----ActivityStackSuperviso.startActivityUncheckedLocked首先判斷了啟動模式------上面的步驟完成了Activity的目標棧的判斷(targetStack)------ActivityStack.startActivityLocked將Activity新增到了棧頂,初始化了WindowManager--------StackSupervisor.resumeTopActivitiesLocked
ActivityStack.startPausingLocked-------ApplicationThread.schedulePauseActivity主要handler傳送訊息-----ApplicationThread.handlePauseActivity----ApplicationThread.performPauseActivity----- callCallActivityOnSaveInstanceState(r)
----Instrumentation.callActivityOnPause---Activity.performPause---Activity.onPause()
ApplicationThread.handleReusmeActivity----ApplicationThread.performReusmeActivity-----
Instrumentation.callActivityOnReusme---Activity.performReusme---Activity.onReusme()
ActivityStackSupervisor.startSpecificActivityLocked------ActivityManagerService.startProcessLocked-----Process.start方法,並且傳入類名android.app.ActivityThread-------startViaZygote-----zygoteSendArgsAndGetResult最後通過Zygote孵化出了我們剛才傳入的ActivityThread,也就是我們很熟悉的應用入口程序,來到它的main方法----ActivityThread.main()------ Looper.prepareMainLooper()Looper.loop();
----ActivityThread thread = new ActivityThread(); thread.attach(false)---------ActivityManagerService.attachApplication----------ActivityManagerService.attachApplicationLocked-------ActivityStackSupervisor.realStartActivityLocked-------ApplicationThread.scheduleLaunchActivity-----ActivityThread.handleLaunchActivity----ActivityThread.performLaunchActivity----packageInfo.getClassLoader()
mInstrumentation.newActivity----- activity.attach(
---- mInstrumentation.callActivityOnCreate activity.performStart();
mInstrumentation.callActivityOnRestoreInstanceState(
----- prePerformCreate(activity); activity.performCreate(icicle, persistentState); postPerformCreate(activity);
---activity.performCreate()----activity.Create()
Looper.loop();
----ActivityThread thread = new ActivityThread(); thread.attach(false)---------ActivityManagerService.attachApplication----------ActivityManagerService.attachApplicationLocked-------ActivityStackSupervisor.realStartActivityLocked-------ApplicationThread.scheduleLaunchActivity-----ActivityThread.handleLaunchActivity----ActivityThread.performLaunchActivity----packageInfo.getClassLoader()
mInstrumentation.newActivity----- activity.attach(
---- mInstrumentation.callActivityOnCreate activity.performStart();
mInstrumentation.callActivityOnRestoreInstanceState(
----- prePerformCreate(activity); activity.performCreate(icicle, persistentState); postPerformCreate(activity);
---activity.performCreate()----activity.Create()