I am struggling to understand the difference between LiveData
being a LifecycleObserver
and the Observer
that the LiveData
object receives in the observe()
method.
Am I right saying that the LiveData
is a LifecycleObserver
and so it knows about the Activity
because of it?
And that the Observer
received in the observe()
method has nothing to do with LifecycleObserver
because it is there just to execute the onChange()
method when there is a change in LiveData
?
Yes.
Yes.
As the name suggests, a
LifecycleObserver
is supposed to keep track of changes happening to the lifecycle of its parent (Activity
orFragment
or any otherLifecycleOwner
), makingLiveData
lifecycle-aware.The
Observer
on the other hand keeps track of changes happening to thevalue
of thisLiveData
object.So you are correct.
Observer
has nothing to do withLifecycleObserver
.