Skip to content

Commit 7b058c0

Browse files
authored
Fix BadTokenException when showing NewAddressBarOptionBottomSheetDialog (#6892)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1211555187913871?focus=true ### Description - Adds a `isWindowValid` check before displaying the dialog. ### Steps to test this PR - [x] Fresh install the app - [x] Complete onboarding (Use "I’ve been here before", **not** “Skip Onboarding”) and kill the app - [x] Verify that the New Address Bar Option Dialog is displayed
1 parent 3061070 commit 7b058c0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/inputscreen/newaddressbaroption/NewAddressBarOptionBottomSheetDialog.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class NewAddressBarOptionBottomSheetDialog(
175175

176176
if (pendingShow) {
177177
pendingShow = false
178-
show()
178+
if (isWindowValid()) { super.show() }
179179
}
180180
}
181181
}
@@ -246,7 +246,7 @@ class NewAddressBarOptionBottomSheetDialog(
246246
playIntroThenLoop(lottieView, it.durationFrames.toInt())
247247
}
248248
}
249-
super.show()
249+
if (isWindowValid()) { super.show() }
250250
} else {
251251
pendingShow = true
252252
}
@@ -257,6 +257,10 @@ class NewAddressBarOptionBottomSheetDialog(
257257
restoreOrientation()
258258
}
259259

260+
private fun isWindowValid(): Boolean = (context as? Activity)?.let { activity ->
261+
!activity.isFinishing && !activity.isDestroyed && activity.window?.decorView?.isAttachedToWindow == true
262+
} ?: false
263+
260264
companion object {
261265
const val MAX_HEIGHT_DP = 900
262266
}

0 commit comments

Comments
 (0)