小编Emi*_*ann的帖子

java中如何收集协程流?

我正在开发一个Android库,

当用户收到推送通知时,它可能包含深层链接,我需要返回到应用程序。

我在 kotlin 中做的没有问题。

这是需要发送深层链接时调用的函数

fun getDeepLinkFlow(): Flow<HashMap<String, String>?> = flow {
    emit(deepLinks)
}
Run Code Online (Sandbox Code Playgroud)

在我的 kotlin 测试应用程序中,我也成功地使用了,就像这样使用。

GlobalScope.launch(coroutineContext) {
    SDK.getDeepLinkFlow().collect { deepLinks ->
        println(deepLinks)
    }
}
Run Code Online (Sandbox Code Playgroud)

但现在,有一个 RN 项目想要使用该库,为了做到这一点,我们正在做一个 RN 模块,将 iOS 代码和 Android 代码结合起来。但它使用java。

那么,如何在 Java 代码上使用协程的收集功能呢?或者我可以做些什么不同的事情?

java android coroutine kotlin kotlin-coroutines

6
推荐指数
1
解决办法
6301
查看次数

标签 统计

android ×1

coroutine ×1

java ×1

kotlin ×1

kotlin-coroutines ×1