We know the old android architecture components like Linux kernel, native libraries, android runtime, application framework, and applications.
Google has launched 14 different versions of android OS but one thing to notice is that there was not a good architecture to follow or to maintain your code better. But in now Google I/O has announced a new Android Architecture components that will help us to maintain our code robust, testable, maintainable and easily readable. The new pattern announced by Google is MVVM i.e model view view-model pattern that is reactive and removes lots of boiler plate codes.
Android Architecture Components
There are 4 components now:
Let's see all one by one.
1. Live Data
Live data is just an observable data holder that notify observer about the data changes so that we can update the UI easily.
Live data can be of any type like this:
Live data works with Lifecycle component to check the current state of activity like on screen, off screen or destroy so live data update UI only when activity is visible.
2. Life Cycle
We know that live data send an update to UI only when activity is not off screen or destroy. Live data uses 2 lifecycle interfaces for this, that is LifeCycleOwner and LifeCycleObserver.
LifeCycleOwner: These are the fragments or activities.
LifeCycleObserver: This is Lifecycle observer that observe lifecycle owner.
3. View Model
View Model are objects that holds live data and other data for UI and also control configuration changes.
we have already discussed this in our previous tutorial, please click on below link: