What is the difference between LiveData and LifecycleObserver
They are really different things which serves two separate roles. In short,
LifeCycle
addresses the Android lifecycle problems in effective and easy ways. It has two main parts.LifecycleOwner
exposes its state changes, andLifecycleObserver
listens to these changes to make appropriate steps.LiveData
, on the other hand, leverages reactive programming which helps us manipulate data easily. It shares some similarities withStream
inJava 8
andObserver
(orFlowable
) inRxJava
. However, LiveData has an advantage is that it is lifecycle-aware specific for Android. So, it works closely with LifeCycle components.
From a higher abstraction level, I think that:
- LiveData is a data holder which host some data, with the difference that it's LifeCycle Aware. So it's an observable data holder, not an observer!
- LifecycleObserver on the other hand is an observer who cares about lifecycles.
I believe that is the main distinction.