As ViewModelProviders.of() is deprecated, How should i create object of ViewModel?

前端 未结 10 1075
情深已故
情深已故 2020-12-14 14:05

I have been trying to create an Object of ViewModel in an Activity but ViewModelProviders is deprecated So what\'s the alternative to create the ViewModel\'s object.

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 14:18

    This class is deprecated. Use the constructors for ViewModelProvider directly. here

    So instead of using this

    ViewModelProviders.of(this).get(MyViewModel.class); - deprecated
    

    Use this one

    new ViewModelProvider(this).get(MyViewModel.class); - correct
    

提交回复
热议问题