ViewModel

ViewModel is a class that is responsible for preparing and managing the data for
an Activity or a Fragment.
It also handles the communication of the Activity / Fragment with the rest of the application
(e.g. calling the business logic classes).

A ViewModel is always created in association with a scope (an fragment or an activity) and will
be retained as long as the scope is alive. E.g. if it is an Activity, until it is
finished.

In other words, this means that a ViewModel will not be destroyed if its owner is destroyed for a
configuration change (e.g. rotation). The new instance of the owner will just re-connected to the
existing ViewModel.

The purpose of the ViewModel is to acquire and keep the information that is necessary for an
Activity or a Fragment. The Activity or the Fragment should be able to observe changes in the
ViewModel. ViewModels usually expose this information via LiveData or Android Data
Binding. You can also use any observability construct from you favorite framework.

ViewModel's only responsibility is to manage the data for the UI. It should never access
your view hierarchy or hold a reference back to the Activity or the Fragment.

ViewModels can also be used as a communication layer between different Fragments of an Activity.
Each Fragment can acquire the ViewModel using the same key via their Activity. This allows
communication between Fragments in a de-coupled fashion such that they never need to talk to
the other Fragment directly.