Viewmodel
To use viewmodel first need to add gradle dependency
make new kotlin file with appropriate viewmodel name
Add init block and override onCleared
. Add log statements to both
Create a field for the viewmodel class we created in the recquired activity
Inside oncreate of class or fragment initialize viewmodel
now place the logic codes in the viewmodel class
view model should never hold references to activities or fragments.
UI controller(activity) should be as simple as possible
Last updated