Best Practises In ViewModel

Why do we need ViewModel?

In Android, UI state get’s destroyed during configuration changes like screen rotation, screen size changes etc. To persist the UI state and to access business logic, we need a plan class named ViewModel able to persist the UI state during configuration changes and process death.

Internally, ViewModel works with activity or fragment lifecycle, it’s doesn’t get destroyed when activity or fragment invokes the onDestory() during configuration changes.

Learn More