-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setEventListener leaks fragment #48
Comments
That sounds really nice! |
Yeah, I can definitely contribute if you don't mind adding new dependency on lifecycle architecture components. |
AppCompat has a dependency on AndroidX Lifecycle, and there are few apps without it(I guess), so let's do it 😄 |
I have created the following PR. However I'm not sure about all the bells and whistles around bumping version numbers, publishing, etc. Can you please help me? |
When calling setEventListener from fragment instance the listener does not get unregistered when the fragment is destroyed. The reason is simple - this library registers activity lifecycle observer, but the activity outlives fragments.
At minimum this causes fragment leak, in worst case scenario it causes application crash in case the event listener touches dead fragment views/data bindings.
What we would like to have added is to use Architecture Components lifecycle support, so in addition to activity there would be a
LifecycleOwner
passed tosetEventListener
where you can then observe its lifecycle and unregister the listener automatically when the owner is destroyed, be itActivity
orFragment
.For now the workaround is to manually unregister the listener in corresponding Fragment's lifecycle methods.
The text was updated successfully, but these errors were encountered: