How to get lifecycle.coroutineScope with new androidx.lifecycle:*:2.2.0-alpha01

前端 未结 2 684
你的背包
你的背包 2021-02-18 15:09

On 7th May, 2019 androidx.lifecycle:*:2.2.0-alpha01 was released announcing:

This release adds new features that adds support for Kotlin coro

相关标签:
2条回答
  • 2021-02-18 15:31

    The accepted answers is working, but I'm misused for the first time, so I'm trying to make it clear, the current version of lifecycle is "2.1.0" and lifecycleScope, and ViewModelScope is not available in this version, to get them use

    For ViewModelScope, use androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0-beta01 or higher.

    For LifecycleScope, use androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha01 or higher.

    at this time 2.3.0-rc01 is available.

    0 讨论(0)
  • 2021-02-18 15:37

    I actually spent a couple hours trying to figure this out myself and it turns out it is in a new package that only exists as of the alpha. Add this and you should be good to go.

    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_ver"
    
    0 讨论(0)
提交回复
热议问题