From d180feb55ffd3f6628930958968d727bf64625af Mon Sep 17 00:00:00 2001 From: caizhixing Date: Mon, 9 Nov 2026 04:49:49 -0800 Subject: [PATCH] fix: crash when the icon surface view still has a parent on resume (#7513) LawnchairFloatingSurfaceView.removeViewImmediate() skipped the removal when isAttachedToWindow was false. onNewIntent is delivered inside performResumeActivity, while the window can still be re-attaching: the view is already a child of the drag layer but not attached yet. The removal was skipped, so the following show() crashed on addView() with IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. FloatingSurfaceView removes the view unconditionally, and removeViewInLayout() is a no-op when the view has no parent, so match it. Co-authored-by: caizhixing --- .../app/lawnchair/views/LawnchairFloatingSurfaceView.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lawnchair/src/app/lawnchair/views/LawnchairFloatingSurfaceView.kt b/lawnchair/src/app/lawnchair/views/LawnchairFloatingSurfaceView.kt index 2ebc1e9319..c4efa321d7 100644 --- a/lawnchair/src/app/lawnchair/views/LawnchairFloatingSurfaceView.kt +++ b/lawnchair/src/app/lawnchair/views/LawnchairFloatingSurfaceView.kt @@ -104,9 +104,12 @@ class LawnchairFloatingSurfaceView @JvmOverloads constructor( private fun removeViewImmediate() { // Cancel any pending remove Executors.MAIN_EXECUTOR.handler.removeCallbacks(mRemoveViewRunnable) - if (isAttachedToWindow) { - removeViewFromParent() - } + // Remove unconditionally, matching FloatingSurfaceView. isAttachedToWindow can be false + // while the view is still a child of the drag layer: onNewIntent is delivered inside + // performResumeActivity, when the window may still be re-attaching. Skipping the removal + // in that window leaves the view with a parent, and the next show() crashes on addView + // with "The specified child already has a parent". + removeViewFromParent() } override fun isOfType(type: Int): Boolean {