如何使用新的androidx.lifecycle:*:2.2.0-alpha01获取lifecycle.coroutineScope [英] How to get lifecycle.coroutineScope with new androidx.lifecycle:*:2.2.0-alpha01

查看:760
本文介绍了如何使用新的androidx.lifecycle:*:2.2.0-alpha01获取lifecycle.coroutineScope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2019年5月7日androidx.lifecycle:*:2.2.0-alpha01发布,宣布:

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

此版本增加了一些新功能,这些功能增加了对Lifecycle和LiveData的Kotlin协程的支持.可以在此处找到有关它们的详细文档.

This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here.

文档中,提到我可以得到LifecycleScope :

On documentation it's mentioned that I can get the LifecycleScope:

通过lifecycle.coroutineScopelifecycleOwner.lifecycleScope属性

但是似乎我找不到它们.我目前的依赖条件是:

But it seems that I'm not able to find none of them. My current dependencises are:

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?

What may be the cause and how do get these apis?

推荐答案

我实际上花了几个小时试图自己弄清楚这一点,结果发现它在一个仅存在于alpha版本的新程序包中.添加此内容,您应该就很好了.

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"

这篇关于如何使用新的androidx.lifecycle:*:2.2.0-alpha01获取lifecycle.coroutineScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆