frameworks/base/core/java/android/view/WindowManagerGlobal.java publicvoidremoveView(View view, boolean immediate) { if (view == null) { thrownewIllegalArgumentException("view must not be null"); }
if (root != null) { root.getImeFocusController().onWindowDismissed(); // 2 } booleandeferred= root.die(immediate); // 3 if (view != null) { view.assignParent(null); if (deferred) { mDyingViews.add(view); } } }
注释1处根据传入的索引在ViewRootImpl列表中获得V的ViewRootImpl。
注释2处结束V的输入法相关的逻辑。
注释3处调用ViewRootImpl的die()方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
frameworks/base/core/java/android/view/ViewRootImpl.java booleandie(boolean immediate) { // Make sure we do execute immediately if we are in the middle of a traversal or the damage // done by dispatchDetachedFromWindow will cause havoc on return. if (immediate && !mIsInTraversal) { // 1 doDie(); // 2 returnfalse; }
if (!mIsDrawing) { destroyHardwareRenderer(); } else { Log.e(mTag, "Attempting to destroy the window while drawing!\n" + " window=" + this + ", title=" + mWindowAttributes.getTitle()); } mHandler.sendEmptyMessage(MSG_DIE); returntrue; }
frameworks/base/core/java/android/view/ViewRootImpl.java voiddoDie() { checkThread(); // 1 if (LOCAL_LOGV) Log.v(mTag, "DIE in " + this + " of " + mSurface); synchronized (this) { if (mRemoved) { // 2 return; } mRemoved = true; // 3 mOnBackInvokedDispatcher.detachFromWindow(); if (mAdded) { // 4 dispatchDetachedFromWindow(); // 5 }
if (mAdded && !mFirst) { // 6 destroyHardwareRenderer();
if (mView != null) { intviewVisibility= mView.getVisibility(); booleanviewVisibilityChanged= mViewVisibility != viewVisibility; if (mWindowAttributesChanged || viewVisibilityChanged) { // If layout params have been changed, first give them // to the window manager to make sure it has the correct // animation info. try { if ((relayoutWindow(mWindowAttributes, viewVisibility, false) & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { mWindowSession.finishDrawing( mWindow, null/* postDrawTransaction */, Integer.MAX_VALUE); } } catch (RemoteException e) { } }
destroySurface(); } }
// If our window is removed, we might not get notified about losing control. // Invoking this can release the leashes as soon as possible instead of relying on GC. mInsetsController.onControlsChanged(null);