Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

06.2 ViewModelProviders is deprecated #33

Closed
ianchen-tw opened this issue Feb 11, 2020 · 4 comments
Closed

06.2 ViewModelProviders is deprecated #33

ianchen-tw opened this issue Feb 11, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ianchen-tw
Copy link

similar to #29

Describe the problem
The ViewModelProviders is deprecated, use ViewModelProvider directly.

In which lesson and step of the codelab can this issue be found?

06.2 Task 4 and probably every paragraph after that

Additional information

Replace every occurrence of

val sleepTrackerViewModel =
       ViewModelProviders.of(
               this, viewModelFactory).get(SleepTrackerViewModel::class.java)

to

val sleepTrackerViewModel =
       ViewModelProvider(
               this, viewModelFactory).get(SleepTrackerViewModel::class.java)

codelab: android-kotlin-fundamentals

@AayuStark007
Copy link

Hi, Can I submit a PR for fixing this issue?
My changes would be to refactor the code to replace the occurrences of ViewModelProviders.of() to ViewModelProviders() in the code and include appropriate import statements for the same.

@amberream
Copy link

The code codelab may have changed since this issue was initially submitted because it's now a charades game rather than a sleep tracker. I changed the code to this:

Log.i("GameFragment", "Called ViewModelProviders.of")
//        viewModel = ViewModelProviders.of(this).get(GameViewModel::class.java)
viewModel = ViewModelProvider(this).get(GameViewModel::class.java)

@anotheraccountusername
Copy link

The code codelab may have changed since this issue was initially submitted because it's now a charades game rather than a sleep tracker. I changed the code to this:

Actually sleep tracker is in the 6.x codelabs. Anyway your solution will work in both.

@android-dev-lxl
Copy link
Contributor

fixed

k12e5989 pushed a commit to k12e5989/android-kotlin-fundamentals-apps that referenced this issue Dec 2, 2020
…-training/retrofit-callbacks

Uses Retrofit *Call* callbacks vs discrete types/suspend functions
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants