Search code examples
androidandroid-architecture-components

ObservableField or LiveData? Which one is the best?


I have been testing Livedata and AAC in general.

What is the core difference between LiveData and ObservableField?

Which one is the best and when should I use one over another?


Solution

  • The core difference is that ObservableField<T> is not lifecycle-aware and hence there cannot be any automatic subscription management. While LiveData<T> is lifecycle-aware and solves tons of headaches with subscription management when it comes to Activity/Fragment lifecycles.

    There is no one way to answer what is the best to use. It is a personal choice, but I would suggest using LiveData<T> just to save yourself some time and avoid potential issues in the future.