Skip to content

Commit 90f4ce1

Browse files
committed
Handle detached from window to avoid fragment leak
1 parent 702b0ea commit 90f4ce1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutActivity.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,17 @@ class CheckoutActivity : FragmentActivity() {
298298
headlessFragment = foundFragment
299299
}
300300
}
301+
302+
override fun onDetachedFromWindow() {
303+
super.onDetachedFromWindow()
304+
val activity = requireFragmentActivity()
305+
headlessFragment?.let { fragment ->
306+
if (!activity.isChangingConfigurations) {
307+
activity.supportFragmentManager.beginTransaction()
308+
.remove(fragment)
309+
.commitAllowingStateLoss()
310+
}
311+
}
312+
headlessFragment = null
313+
}
301314
}

0 commit comments

Comments
 (0)