android - Retrofit调用enqueue方法或者Rxjava

标签 android retrofit rx-java rx-android

作为改造 docs在 Retrofit 中表示 Call enqueue 方法是:

Asynchronously send the request and notify callback of its response or if an error occurred talking to the server, creating the request, or processing the response.

和 Rxjava according to this tutorial是:

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming

这两个似乎有相同的方法。各自的优点和缺点是什么?哪个更好用?

最佳答案

我不会说他们有相同的方法。 Retrofit 专为 API 调用而设计,可以同步或异步地为您调用 API(您可以指定)。虽然 RxJavaRxAndroid 可以为您做类似的事情(即同步或异步执行一些任务),但它不仅限于 API 调用。你可以用 RxJava/Android

创造许多奇迹

正如你所引用的那样

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming

RxJavaRxAndroid 使用函数响应式编程 (FRP) 的原则来做到这一点。 FRP 与 Retrofit 无关,因此它们不相同,无法比较。

您还可以使用 RxJava/Android 和 Retrofit 来调用 FRP 模式中的 API。

请阅读this这样您就可以对 FRP 有更多的了解:

你应该阅读 this以及了解运算符的作用 RxJava 提供的内容以及如何使用它们

最后,如果 Asynchronous 只是指 API 调用,那么 Retrofit 更好,因为它是专门为此设计的,如果 Asynchronous 你的意思是其他一些任务,比如资源密集型等等,那么如果你想要 FRP 模式中的异步任务,比如 Observer,显然 RxJava/Android 会更好可观察

关于android - Retrofit调用enqueue方法或者Rxjava,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46088566/

相关文章:

android - 如何在 android 中获取 Retrofit 错误消息?

scala - 可观察的异常处理

java - RxJava - 当同时使用observeOn和subscribeOn时,ConnectableObservable无法通知其观察者超过128次

Android LinearLayout 触摸移动

android - 仅在 Android 6 上存在安全异常

android - 改造多个 POST 参数

kotlin - 使用 RxJava 构建 "task queue"的最佳方式

android - CrossAxisAlignment.center 从不在 Column 中工作

安卓工具栏标题

安卓 : Wireless access point session timeout and HostnameValidation errors