Looking at the Google docs for ViewModel, they show the below sample code on how to get a ViewModel:
val model = ViewModelProviders
As of 2.2.0. the lifecycle-extensions has been deprecated. Refer to Google Documentation.
This is the cut from the page:
The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need.
The new libraries are:
// ViewModel and lifecycle support for java
implementation "androidx.lifecycle:lifecycle-viewmodel:${versions.lifecycle}"
implementation "androidx.lifecycle:lifecycle-livedata:${versions.lifecycle}"
// ViewModel and lifecycle support for kotlin
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.lifecycle}"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:${versions.lifecycle}"
The new code for JAVA:
viewModel = new ViewModelProvider(this).get(MyViewModel.class);
Or for Kotlin:
viewModel = ViewModelProvider(this).get(MyViewModel::class.java)