android – 使用subscribeOn和Retrofit

android – 使用subscribeOn和Retrofit,第1张

概述关于何时以及是否将subscribeOn与Retrofit一起使用存在冲突的信息. Here is an answer说不要使用subscribeOn. Here is an answer似乎暗示subscribeOn没有好的默认设置. Here is example code使用subscribeOn. 那么,一劳永逸,我什么时候应该使用subscribeOn和什么线程?使用或不使用subscr 关于何时以及是否将subscribeOn与Retrofit一起使用存在冲突的信息.

Here is an answer说不要使用subscribeOn.
Here is an answer似乎暗示subscribeOn没有好的默认设置.
Here is example code使用subscribeOn.

那么,一劳永逸,我什么时候应该使用subscribeOn和什么线程?使用或不使用subscribeOn可能会产生什么影响?

APIService.issueRequest()    // Is this useful? required? Bad practice?    .subscribeOn(Schedulers.io())    // Do actions on main thread    .observeOn(AndroIDSchedulers.mainThread())    .subscribe(new Action1<Response>() {        @OverrIDe public voID call(Response response) {            handleResponse(response);    });
解决方法 在当前版本的Retrofit(1.9.0)中,Retrofit使用自己的执行程序来执行http调用,而不使用subscribeOn方法给出的 the executor backed by the schedulers.

在您的情况下,调度程序将仅用于执行将http调用添加到改造使用的执行程序的代码. (所以它有点无用……)

但是,关于Retrofit on Github的实际代码,改造停止使用他的执行程序,因此可以使用RxJava调度程序.

总结

以上是内存溢出为你收集整理的android – 使用subscribeOn和Retrofit全部内容,希望文章能够帮你解决android – 使用subscribeOn和Retrofit所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1136548.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存