androidx.lifecycle:lifecycle-*:2.2.0 中 ViewModelProviders被弃用。
但在官方文档中还未更新,还是使用的
MyViewModel model = ViewModelProviders.of(this).get(MyViewModel.class);
最后在更新文档中找到了:
ViewModelProviders.of() deprecation: ViewModelProviders.of() has been deprecated. You can pass a Fragment or FragmentActivity to the new ViewModelProvider(ViewModelStoreOwner) constructor to achieve the same functionality when using Fragment 1.2