All about ViewModel and Its working.
Hello friends hi. This post is regarding all about the ViewModel and It's working. Well, ViewModel is the part of the MVVM ( Model-View-ViewModel ) architectural pattern. The ViewModel class is a business logic or screen level state holder . It exposes state to the UI and encapsulates related business logic. In more simple words, ViewModel is used to persist the state on configuration changes like Screen Rotation, Keypad show or hide etc. It's a lifecycle aware component which means it work with respect to the lifecycle of an Activity or Fragment. Because it associated with Views as shown in following... As we can see that the onCleared() method of the ViewModel is invoked just before the onDestroy() method of the Activity. The tasks which are no longer need in the memory is usually written in the onCleared() method of the ViewModel. Example:- Cancellation of a Coroutine. Working of ViewModel: There are three terms related to ViewModel to un...