As of 2019, I'm trying to follow a best practice on where to start observing LiveData
in Fragments and if I should pass this
or viewLifecycleOwner
as a parameter to the observe()
method.
According to this Google official documentation, I should observe in
onActivityCreated()
passingthis
(the fragment) as parameter.According to this Google sample, I should observe in
onViewCreated()
passingviewLifecycleOwner
as parameter.According to this I/O video, I shouldn't use
this
but insteadviewLifecycleOwner
, but doesn't specify where should I start observing.According to this pitfalls post, I should observe in
onActivityCreated()
and useviewLifecycleOwner
.
So, where should I start observing? And should I either use this
or viewLifecycleOwner
?