1, create a

public void handleLaunchActivity(IBinder token, boolean finalStateRequest, boolean isForward, String reason) { ... ; / / here to initialize WindowManagerGlobal WindowManagerGlobal. The initialize (); Final Activity A = performLaunchActivity(r, customIntent); . } private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {try {/ / here create Application Application app = r.p. AckageInfo makeApplication (false, mInstrumentation); . if (activity ! = null) { ... Window window = null; if (r.mPendingRemoveWindow ! = null && r.mPreserveWindow) { window = r.mPendingRemoveWindow; r.mPendingRemoveWindow = null; r.mPendingRemoveWindowManager = null; } appContext.setOuterContext(activity); Attach (appContext, this, getInstrumentation(), r.token, r.ident, app, r.intent, r.activityInfo, title, r.parent, r.embeddedID, r.lastNonConfigurationInstances, config, r.referrer, r.voiceInteractor, window, r.configCallback, r.assistToken); . / / the last callback the Activity's onCreate method here if (r.i sPersistable ()) {mInstrumentation. CallActivityOnCreate (Activity, r.s Tate, r.persistentState); } else { mInstrumentation.callActivityOnCreate(activity, r.state); }}... } final void attach(... ,Context context,Window window, ...) {... ; MWindow = new PhoneWindow(this, window, activityConfigCallback); / / the Activity implementation window callBack interface, set himself to window mWindow. SetWindowControllerCallback (this); mWindow.setCallback(this); mWindow.setOnWindowDismissedCallback(this); mWindow.getLayoutInflater().setPrivateFactory(this); . // Initialize the window's WindowManager object mwindow.setwinDowManager ( (WindowManager)context.getSystemService(Context.WINDOW_SERVICE), mToken, mComponent.flattenToString(), (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) ! = 0); }Copy the code

2. Add view to window

SetContentView public void setContentView(int layoutResID) {// Create a DecorView if (mContentParent == null) { installDecor(); } else if (! hasFeature(FEATURE_CONTENT_TRANSITIONS)) { mContentParent.removeAllViews(); } if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { final Scene newScene = Scene.getSceneForLayout(mContentParent, layoutResID, getContext()); transitionTo(newScene); } else {// Here the layout mLayOutinflater.inflate (layoutResID, mContentParent) is loaded according to the layout ID; } mContentParent.requestApplyInsets(); final Callback cb = getCallback(); if (cb ! = null && ! IsDestroyed ()) {cb.onContentChanged(); } mContentParentExplicitlySet = true; } Since then, there has been a View in phoneWindow decor.Copy the code

3. Add the decorView as window to the screen

public void handleResumeActivity(IBinder token, boolean finalStateRequest, boolean isForward, String Reason) {// Call the Activity's onResume method final ActivityClientRecord r = performResumeActivity(token, finalStateRequest, reason); . / / let decorView displayed on the screen if (state Richard armitage ctivity. MVisibleFromClient) {state Richard armitage ctivity. MakeVisible (); } void makeVisible() { if (! mWindowAdded) { ViewManager wm = getWindowManager(); wm.addView(mDecor, getWindow().getAttributes()); mWindowAdded = true; } mDecor.setVisibility(View.VISIBLE); }Copy the code

The window is added after onResume. I’m going to draw the view,