Issue
This is a very simple question:
Background
I'm using the relatively new Lifecycle class (part of the android architecture components libraries) to handle some events of the Activity/Fragment
in an easier way.
This is how you use it for handling ON_DESTROY event:
lifecycle.addObserver(object : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() {
lifecycle.removeObserver(this)
//Do something
}
})
The problem
I can't find in the docs and here, whether I should call removeObserver
or that it's done automatically anyway upon the ON_DESTROY event.
What I've tried
I tried to read about it, and for now as a precaution I always call removeObserver
.
The question
Is it safe to avoid calling removeObserver
upon ON_DESTROY event?
Solution
There is one chain of discussion over github related this topic.
as far as I know, no need to call removeObserve
explicitly.
The only reason is lifecycle-aware components are specifically design to make sure this callbacks.
Hear is the link you can refer, https://github.com/googlecodelabs/android-lifecycles/issues/5
Answered By - Radhey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.