2019 年 5 月 7 日 androidx.lifecycle:*:2.2.0-alpha01
发布公告:
This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here.
关于 documentation提到我可以获得 LifecycleScope
:
either via
lifecycle.coroutineScope
orlifecycleOwner.lifecycleScope
properties
但是我好像一个也找不到。我目前的依赖是:
def lifecycle_ver = "2.2.0-alpha01"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_ver"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_ver"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_ver"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1'
可能是什么原因以及如何获取这些api?
最佳答案
我实际上花了几个小时试图自己解决这个问题,结果发现它在一个新包中,该包仅在 alpha 版中存在。添加这个,你应该可以开始了。
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_ver"
关于android - 如何使用新的 androidx.lifecycle :*:2. 2.0-alpha01 获取 lifecycle.coroutineScope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56035176/