main入口函数创建了一个ActivityThread对象之后,通过bindler机制 回调了handleLaunchActivity()方法 ->
ActivityThread#handleLaunchActivity ->
WindowManagerGlobal.initialize() ; performLaunchActivity ->
activity = mInstrumentation.newActivity(r.packageInfo.getClassLoader()) ; activity.attach() ->
mWindow = new PhoneWindow();installDecor创建出DecorView; mWindow.setCallback(this)(事件分发用到这个) ->
performLaunchActivity返回了activity实例,不为空的话 ->
ActivityThread#handleResumeActivity
把view显示到屏幕上的过程:
ActivityThread#handleResumeActivity ->
windowManager.addView(decor) ->
windowManagerImpl.addView(decor) ->
windowManagerGlobal.addView(decor) ->
root = new ViewRootImpl; root.setView(decor) ->
requestLayout; mWindowSession.addToDisplay()(IPC), 这样view显示到屏幕中了
其中:setContentView是把layout加载后挂到decorView的R.id.content的fragment中。
注意过程中的一些概念:
ActivityThread
WindowManager
WindowManagerImpl
WindowManagerGlobal
PhoneWindow
DecorView
ViewRootImpl