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);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)