Use a ViewModel | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/7503473-your-second-kotlin-android-app/lessons/42

Doing this at the end of August, it inserts

‘androidx.lifecycle:lifecycle-extensions:2.2.0’

into my grade but in version 2.2 ViewModelProviders is deprecated. So I downgraded it to version 2.1 and it seems to work so far. From the documentation it appears in 2.2 one can just do

ViewModelProvider.get(xxxx)

But I was never able to get the “get” to import so I just downgraded rather than mess with it.

Sorry to be a pest – I’m also a bit confused by

    activity?.let {
        listDataManager = ViewModelProviders.of(this).get(ListDataManager::class.java)
    }

    val lists = listDataManager.readLists()

I am new to Kotlin but I am not clear why the listDataManager instantiation is inside a let block. But given that it is, shouldn’t the readLists method be inside as well, as if there is no activity then the listDataManager won’t be created and invoking readlLists on it would cause a crash. I also realize if there is not activity you have bigger problems :slight_smile:

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

Is there any plan to update the android video courses? I like these contents ,but some is too old (2020) to easily follow

Yes, we are in the process of updating all of our Android tutorials. This course is slated to be updated later this year. To follow along, you can always download the version of Android Studio that was used to produce this version of the course (Android Studio 3.5).