Activity 的启动

2018-11-27  本文已影响0人  Wi1ls努力努力再努力

Activity 的启动最后转到目标进程的 ActivityThread 处理
关键类是ActivityThread$H

一部分完成。

在onCreate( )@Instrumentation 中,一般会进行setContentView( )

@Override
protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_man);
}

public void setContentView(int layutResId)@PhoneWindow

关键函数installDecor( );

至此,
1.生成一个Decor 的 FrameLayout 作为顶层的布局,作为mDecor;
2.根据不同的配置选择不同的系统资源文件实例化一个布局作为mContentRoot 添加到 mDecor;这个 mContentRoot 根据选择的主题等可能含有 Title,Bar 等其他 SystemUI,统一的是均含有com.android.internal.R.id.content 的 FrameLayout 的子 View
3.在 mContentRoot中选择id 为com.android.internal.R.id.content 的 子 View,FrameLayout 作为mContentParent;
3.实例化用户传入的布局layoutResID,作为子 View 添加到 mContentParent 中

二部分完成。

在一部分完成后,即onCreate( );onPostCreate( );onStart( )完毕后,

View decor = r.window.getDecorView( );
ViewManager wm = a.getWindowManager( );
a.mDecor = decor;
wm.addVeiew(decor, l);//关键函数,这里的 wm 是WindowManagerImpl 类

addView( )@WindowManagerImpl

public void addView(View view,ViewGroup.LayoutParams params){
  mGlobal.addView(view, params, mDisplay, mParentWindow);
}

addView( )@WimdowManagerGlobal

public void addView(View view, ViewGroup.LayoutParams params, Display diaplay, Window parentWindow){
  ViewRootImpl root;
  view panelParentView =null;
  ...
  root = new ViewRootImpl(view.getContext( ), diaplay);
  view.setLayoutParams(wmarams);
 
  mViews.add(view);
  mRoots.add(root);
  mParams.add(wparams);

  root.setView(view, wparams, panelParentView);
}

setView( )@ViewRootImpl


上一篇 下一篇

猜你喜欢

热点阅读