Skip to content

Commit bbb2b4c

Browse files
ADFA-3418: Register the flashbar config callback on attach, not in show()
Unregistering on detach alone did not clear the leak: a LeakCanary dump after backgrounding still showed the callback holding a destroyed EditorActivityKt. Register in onAttachedToWindow so the callback exists only while the bar is attached, paired with the detach unregister.
1 parent bf8aded commit bbb2b4c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎subprojects/flashbar/src/main/java/com/itsaky/androidide/flashbar/FlashbarContainerView.kt‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ internal class FlashbarContainerView(context: Context)
8686

8787
private var configCallbacks: ComponentCallbacks? = null
8888
private var registeredActivity: Activity? = null
89+
private var hostActivity: Activity? = null
8990

9091
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
9192
when (event.action) {
@@ -106,8 +107,13 @@ internal class FlashbarContainerView(context: Context)
106107
return super.onInterceptTouchEvent(event)
107108
}
108109

109-
// The dismiss paths unregister from a post{}, which never runs once the view is detached, so a
110-
// bar still up when its activity is destroyed left the callback holding that activity.
110+
// The callback is paired with the window attachment so it cannot outlive it. Registering in show()
111+
// relied on the dismiss paths, whose post{} never runs once the view is detached.
112+
override fun onAttachedToWindow() {
113+
super.onAttachedToWindow()
114+
hostActivity?.let { registerConfigurationCallback(it) }
115+
}
116+
111117
override fun onDetachedFromWindow() {
112118
super.onDetachedFromWindow()
113119
unregisterConfigurationCallback()
@@ -184,8 +190,8 @@ internal class FlashbarContainerView(context: Context)
184190

185191
// Only add the withView to the parent once
186192
if (this.parent == null) {
193+
hostActivity = activity
187194
activityRootView.addView(this)
188-
registerConfigurationCallback(activity)
189195
post {
190196
adjustOrientation(activity)
191197
ViewCompat.requestApplyInsets(this)

0 commit comments

Comments
 (0)