gpt4 book ai didi

android - 如何在 Android 架构组件中使用 RxJava 而不是 LiveData?

转载 作者:搜寻专家 更新时间:2023-11-01 07:43:21 25 4
gpt4 key购买 nike

Note: If you are already using a library like RxJava or Agera, you can continue using them instead of LiveData. But when you use them or other approaches, make sure you are handling the lifecycle properly such that your data streams pause when the related LifecycleOwner is stopped and the streams are destroyed when the LifecycleOwner is destroyed. You can also add the android.arch.lifecycle:reactivestreams artifact to use LiveData with another reactive streams library (for example, RxJava2).

上面的语句是从android开发者页面复制的。这里它指定如果你使用的是RxJava,你不需要使用LiveData。因为两者都遵循Observable Patters。我想知道如何使用RxJava而不是LiveData来调用rest api。我尝试了很多但找不到任何答案。如果有人帮助我解决这个问题,那就太好了。提前致谢

最佳答案

看看

https://developer.android.com/reference/android/arch/lifecycle/LiveDataReactiveStreams

RxJava 的 Flowable 实现了 Publisher 接口(interface)。您可以将 LiveData 转换为 Flowable 并从那里开始。

关于android - 如何在 Android 架构组件中使用 RxJava 而不是 LiveData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50289908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com