How to get an Instance of ViewModel in activity in 2020/21?
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);