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
You should update your gradle file to:
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
And due to this change you can pass Activity to the constructor you mentioned:
mainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);