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
LifecycleObserveris supposed to keep track of changes happening to the lifecycle of its parent (ActivityorFragmentor any otherLifecycleOwner), makingLiveDatalifecycle-aware.The
Observeron the other hand keeps track of changes happening to thevalueof thisLiveDataobject.So you are correct.
Observerhas nothing to do withLifecycleObserver.