1. 程式人生 > >activity啟動流程速記筆記

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.resumeTopActivityLocked確保當前棧頂的Activity是否resumed-------ActivityStack.resumeTopActivityInnerLocked 1,首先讓現在正在執行的Activity呼叫startPausingLocked進入pause狀態 2.如果要啟動的Activity不為空且所在的程序存在的話,所在的程序執行scheduleResumeActivity啟動Activity  3.如果Activity為空,所在的程序不存在,執行ActivityStackSupervisor.startSpecificActivityLocked

 

 

 

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()