Android版本:7.0(API27)bash
本篇文章的目的是爲了從Activity的啓動分析出各種事件的開始入口,例如PhoneWindow的建立、繪製流程、觸摸事件分發、按鍵事件分發。這些內容後續文章我會一一分析,因此你們簡單理解Activity的啓動過程便可。
Activity的啓動咱們從startActivity提及,下圖是啓動過程的函數調用路徑:函數
Activity.startActivity()->
startActivityForResult()->
Instrumentation.execStartActivity()->
ActivityManagerService.startActivity()->
startActivityAsUser()->
ActivityStarter.startActivityMayWait()->
startActivityLocked()->
startActivity()->
startActivity()->
startActivityUnchecked()->
ActivityStackSupervisor.resumeFocusedStackTopActivityLocked()->
ActivityStack.resumeTopActivityUncheckedLocked()->
resumeTopActivityInnerLocked()->
ActivityStackSupervisor.startSpecificActivityLocked()->
realStartActivityLocked()->
ActivityThread.ApplicationThread.scheduleLaunchActivity()->
ActivityThread.handleLaunchActivity()->
performLaunchActivity()
handleResumeActivity()
複製代碼
最後Activity的啓動過程由ActivityThread的handleLaunchActivity來完成,handleLaunchActivity中關鍵源碼以下:spa
private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent, String reason){
....
Activity a = performLaunchActivity(r, customIntent);
....
handleResumeActivity(r.token, false, r.isForward,
!r.activity.mFinished && !r.startsNotResumed, r.lastProcessedSeq, reason);
}
複製代碼
performLaunchActivity和handleResumeActivity纔是咱們後續分析須要重點關注的方法。code