

Proper configuration changes: If an activity or fragment is recreated due to a configuration change, like device rotation, it immediately receives the latest available data. For example, an activity that was in the background receives the latest data right after it returns to the foreground. LiveData automatically manages all of this since it’s aware of the relevant lifecycle status changes while observing.Īlways up to date data: If a lifecycle becomes inactive, it receives the latest data upon becoming active again.

No more manual lifecycle handling: UI components just observe relevant data and don’t stop or resume observation. No crashes due to stopped activities: If the observer's lifecycle is inactive, such as in the case of an activity in the back stack, then it doesn’t receive any LiveData events. No memory leaks: Observers are bound to Lifecycle objects and clean up after themselves when their associated lifecycle is destroyed. Instead of updating the UI every time the app data changes, your observer can update the UI every time there's a change. You can consolidate your code to update the UI in these Observer objects. LiveData notifies Observer objects when the lifecycle state changes. This awareness ensures LiveData only updates app component observers that are in an active lifecycle state.Įnsures your UI matches your data state: LiveData follows the observer pattern. Unlike a regular observable, LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services. LiveData: LiveData is an observable data holder class. Its concept is to separate data presentation logic from business logic by moving it into particular class for a clear distinction. MVVM: Model-View-ViewModel (i.e MVVM) is a template of a client application architecture, proposed by John Gossman as an alternative to MVC and MVP patterns when using Data Binding technology. What is MVVM, LiveData, ViewModel, Model, Repository?Īnswer: Let’s see what are the important concepts in MVVM.
