holder class.) • lifecycle-aware observable (Unlike a regular observable, LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services) • Manage Subscription itself (LiveData only notifies to active observer only if it’s activity state in STARTED or RESUMED)
the LiveData object has an active observer. This means you need to start observing the CRYPTO PRICE updates from this method. • onInactive() The onInactive() method is called when the LiveData object doesn't have any active observers. Since no observers are listening, there is no reason to stay connected to the CRYPTO MANAGER service. • setValue(T) The setValue(T) method updates the value of the LiveData instance and notifies any active observers about the change. • postValue(T) The postValue(T) method works similarly as setValue(T) but this method useful while in worker/ background thread.
UI-related data in a lifecycle conscious way. • Viewmodel can save large data as compare to onSavedInstance(). • it can survive configuration changes. • clear automatically when activity destroyed • don’t reference your view inside view model • Now it can be GOAL KEEPER to call an APIs.