android Activity启动过程(二)

Activity在oncreate中调用setContentView方法,该方法体主要是调用 getWindow().setContentView(layoutResID);getWindow返回类型为PhoneWindow,phonewindow的setContentView方法体

283     public void setContentView(View view, ViewGroup.LayoutParams params) {
284         if (mContentParent == null) {
285             installDecor();//主要是生成DecorView对象
286         } else {
287             mContentParent.removeAllViews();
288         }
289         mContentParent.addView(view, params);
290         final Callback cb = getCallback();
291         if (cb != null && !isDestroyed()) {
292             cb.onContentChanged();
293         }
294     }
295 
      private void installDecor() {
2866        if (mDecor == null) {
2867            mDecor = generateDecor();
2868            mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
2869            mDecor.setIsRootNamespace(true);
2870            if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) {
2871                mDecor.postOnAnimation(mInvalidatePanelMenuRunnable);
2872            }
2873        }

生成的DecorView对象,DecorView将view添加进去后就完成了view添加到Activity的过程;DecorView类继承了FrameLayout类,因此向下就进入了View System过程了。


    public void setContentView(View view, ViewGroup.LayoutParams params) {
284         if (mContentParent == null) {
285             installDecor();//主要是生成DecorView对象
286         } else {
287             mContentParent.removeAllViews();
288         }
289         mContentParent.addView(view, params);
290         final Callback cb = getCallback();
291         if (cb != null && !isDestroyed()) {
292             cb.onContentChanged();
293         }
294     }
295 
     private void installDecor() {
2866        if (mDecor == null) {
2867            mDecor = generateDecor();
2868            mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
2869            mDecor.setIsRootNamespace(true);
2870            if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) {
2871                mDecor.postOnAnimation(mInvalidatePanelMenuRunnable);
2872            }
2873        }
}

生成的DecorView对象,DecorView类继承了FrameLayout类,因此向下就进入了View System过程了。



posted @ 2016-03-25 10:34  清澈见底  阅读(110)  评论(0编辑  收藏  举报