The android. 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).
What is the use of ViewModel in Android?
ViewModel Overview Part of Android Jetpack. The ViewModel class is designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.
What is ViewModel factory in Android?
Factory is responsible to create your instance of ViewModel. If your ViewModel have dependencies and you want to test your ViewModel then you should create your own ViewModelProvider. Factory and passed dependency through ViewModel constructor and give value to the ViewModelProvider.