I am new to the mvvm pattern. I created a ViewModel for the main activity. Now I want to get an instance of the ViewModel in the main activity.
Most Tutorials and answe
ViewModel viewModel = ViewModelProviders.of(this).get(ViewModel.class);
Android Support library version is depreciated. So you need to make sure that you import Androidx. And you need to implement androidx dependency in Gradle file.
It is not advised to create a new ViewModel object with "new" keyword.