Activity页面的绘制流程,android开发框架控件主题

View decor = r.window.getDecorView();

decor.setVisibility(View.INVISIBLE);

2.获取WindowManagerImpl对象

ViewManager wm = a.getWindowManager();

WindowManager.LayoutParams l = r.window.getAttributes();

a.mDecor = decor;

l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;

l.softInputMode |= forwardBit;

if (r.mPreserveWindow) {

a.mWindowAdded = true;

r.mPreserveWindow = false;

// Normally the ViewRoot sets up callbacks with the Activity

// in addView->ViewRootImpl#setView. If we are instead reusing

// the decor view we have to notify the view root that the

// callbacks may have changed.

ViewRootImpl impl = decor.getViewRootImpl();

if (impl != null) {

impl.notifyChildRebuilt();

}

}

if (a.mVisibleFromClient) {

if (!a.mWindowAdded) {

a.mWindowAdded = true;

3.调用WindowManagerImpl的addView方法

wm.addView(decor, l);

}

}

}

}

1.我们先来看看注释1

跟一下它的源码,代码只贴主要流程的,有兴趣的朋友可以自己去查看详细的。

@VisibleForTesting

public ActivityClientRecord performResumeActivity(IBinder token, boolean finalStateRequest,

String reason) {

//省略部分代码

final ActivityClientRecord r = mActivities.get(token);

//省略部分代码

//调用Activity的performResume方法

r.activity.performResume(r.startsNotResumed, reason);

return r;

}

final void performResume(boolean followedByPause, String reason) {

//省略部分代码

//调用Instrumentation的callActivityOnResume方法

mInstrumentation.callActivityOnResume(this);

//省略部分代码

}

public void callActivityOnResume(Activity activity) {

activity.mResumed = true;

//调用Activity的onResume

activity.onResume();

if (mActivityMonitors != null) {

synchronized (mSync) {

final int N = mActivityMonitors.size();

for (int i=0; i

final ActivityMonitor am = mActivityMonitors.get(i);

am.match(activity, activity, activity.getIntent());

}

}

}

}

上面我们跟了一下performResumeActivity的源码,发现最后调用了Activity的onResume,由此我们可以知道在注释一的时候,Activity的onResume方法其实已经执行完成了,但是我们的界面绘制还没有开始呢,印证了我们开头说的。

2.下面我们来看看注释2这个wm到底是个什么东西呢,看看

你可能感兴趣的:(程序员,面试,移动开发,android)