ViewModelProviders is deprecated in 1.1.0

后端 未结 22 1439
说谎
说谎 2020-12-07 09:14

Looking at the Google docs for ViewModel, they show the below sample code on how to get a ViewModel:

val model = ViewModelProviders         


        
22条回答
  •  旧巷少年郎
    2020-12-07 09:58

    In case you watch a video from Udacity where you create a GameViewModel and you do not want to write deprecated code just replace:

    viewModel = ViewModelProviders.of(this).get(GameViewModel::class.java)
    

    with the following code:

    viewModel = ViewModelProvider(this).get(GameViewModel::class.java)
      
    

    and return back to reading ASAP!!

提交回复
热议问题