I am trying to create lifecycle-aware view models. But I can't find ViewModelProviders
class in my Android project, only ViewModelProvider
. There seems to be no android.arch.lifecycle.ViewModelProviders
package for me to import as well. What's happening
You probably have this dependency included in your project:
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
That contains ViewModelProvider
(and just 4 other classes), but ViewModelProviders
is in a different package:
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
Here are the contents of these packages for reference (as of version 1.1.1):
For the record, you can find this out yourself by looking up the docs for the ViewModelProviders
class, where it says up top:
added in version 1.1.0
belongs to Maven artifact android.arch.lifecycle:extensions:1.1.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With