window加载

2017-07-11  本文已影响0人  田间小鹿

简书不支持流程图,请看此网页

1.android中UI界面分类

2.activity 创建UI界面过程

graph TB
handleLaunchActivity-->performLaunchActivity
performLaunchActivity-->mInstrumentation.newActivity
performLaunchActivity-->activity.attach
performLaunchActivity-->mInstrumentation.callActiviyOnCreate
activity.attach-->attach
attach-->PhoneWindow
mInstrumentation.callActiviyOnCreate-->setContentView
setContentView -->mDecor_DecorView
setContentView -->mContentParent_ViewGroup
mDecor_DecorView-->generateDecor
mContentParent_ViewGroup-->generateLayout
generateDecor-->mContentParent.addView/mLayoutInflater.inflate
generateLayout-->mContentParent.addView/mLayoutInflater.inflate

上图是activity把UI设置到window上去

这样就把自己的UI设置到window上去了。

3.sub Window关联wms显示到手机上

graph TB 
WindowManager-->|Context.WINDOW_SERVICE|getSystemService
getSystemService-->ContextImp
ContextImp-->SystemServiceRegistry
SystemServiceRegistry-->静态块注册所有服务
静态块注册所有服务-->WindowManagerImpl
WindowManagerImpl-->addView
addView-->WindowManagerGlobal
WindowManagerGlobal-->B[findViewLocked]
WindowManagerGlobal-->panel_window
WindowManagerGlobal-->mWindowSession
mWindowSession-->WindowManagerGlobal.getWindowSession
WindowManagerGlobal.getWindowSession-->IWindowManager.aidl:openSession
IWindowManager.aidl:openSession-->setView
setView-->addToDisplay对应的实现接口为addWindow
addToDisplay对应的实现接口为addWindow-->WindowManagerService_addWindow

这个是子控件怎么显示出来的流程。
上面设置了UI到WM上去。但是怎么显示出来是通过WindowManagerService绑定显示的。

4.application关联wms显示到手机上

sequenceDiagram
ActivityThead.java->>ActivityThead.java:handleLaunchActivity
ActivityThead.java->>WindowManagerGlobal.java:initialize()(创建WMGlobal)
WindowManagerGlobal.java->>WindowManagerGlobal.java:getWindowManagerService
WindowManagerGlobal.java->>IWindowManager.aidl:IWindowManager.Stub.asInterface
ActivityThead.java->>ActivityThead.java:performLaunchActivity
ActivityThead.java->>ActivityThead.java:mInstrumentation.newActivity(创建Activity)
ActivityThead.java->>Activity.java:attach(配置activity)
Activity.java->>PhoneWindow.java:PhoneWindow(创建window)
PhoneWindow.java->>WindowManager.java:setWindowManager(创建WindowManagerImpl实例)
PhoneWindow.java->>WindowManager.java:getWindowManager()
WindowManager.java->>Activity.java:getWindowManager(返回WindowManagerImpl)
ActivityThead.java->>ActivityThead.java:mInstrumentation.callActivityOnCreate(回调onCreate)
Activity.java->>Activity.java:onCreate|setContentView()
Activity.java->>PhoneWindow.java:setContentView()
PhoneWindow.java->>PhoneWindow.java:installDecor()(创建decor和mContentParent)
PhoneWindow.java->>PhoneWindow.java:mLayoutInflater.inflate/mContentParent.addView(把activity中的布局添加到decorview中去)
ActivityThead.java->>ActivityThead.java:handleResumeActivity
Activity.java->>ActivityThead.java:getWindowManager()(返回WindowManagerImpl)
ActivityThead.java->>WindowManagerImpl.java:addView()
WindowManagerImpl.java->>WindowManagerGlobal.java: getInstance(单例初始化)
WindowManagerGlobal.java->>WindowManagerGlobal.java: addView()
WindowManagerGlobal.java->>ViewRootImpl.java:ViewRootImpl(初始化)
WindowManagerGlobal.java->>ViewRootImpl.java:setView()
ViewRootImpl.java->>WindowManagerGlobal.java:getWindowSession()
WindowManagerGlobal.java->>IWindowManager.aidl:openSession
WindowManagerGlobal.java->>ViewRootImpl.java:setView
ViewRootImpl.java->>IWindowSession.aidl:addToDisplay(对应的实现接口为 addWindow())
IWindowSession.aidl->>WindowManagerService.java:addWindow()

上图中设置UI到decorView中的步骤和1一样。
activity设置WMS关联的方式不同。

performTraversals对UI的渲染。

上一篇下一篇

猜你喜欢

热点阅读