RxAndroid 3 主线程 [英] RxAndroid 3 main thread

查看:52
本文介绍了RxAndroid 3 主线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Rx3 中找到 subscribeOn 的主线程

I am trying to find the main thread for subscribeOn in Rx3

Single.just(getHeavyData())
                                .subscribeOn(Schedulers.io())
                                .observeOn(AndroidSchedulers.mainThread())
                                .subscribe(new Consumer<Data>() {
                                    @Override
                                    public void accept(Data d) throws Throwable {
                                        setAdapters(d);
                                    }
                                });

AndroidSchedulers.mainThread() - 与全新的 RX3 不兼容

AndroidSchedulers.mainThread() - is not compatible with the brand new RX3

Gradle 导入:实现io.reactivex.rxjava3:rxjava:3.0.0-RC3"

我们如何找到主线程以对 UI 进行更改?

How can we find the main thread in order to do changes to the UI?

推荐答案

AndroidSchedulers.mainThread() 不是 Rx Java 1,2 或 3 的一部分.它是 RxAndroid 库的一部分.将 RxAndroid 依赖添加到您的项目中,您将获得此方法.

AndroidSchedulers.mainThread() is not part of Rx Java 1,2 or 3. Its the part of RxAndroid Library. Add RxAndroid dependency to your project and you will get this method.

RxAndroid 仍然使用 RxJava2.在库的创建者进行更新之前,此问题仍然存在.

RxAndroid still uses RxJava2. Until there is an update from the creators of the library this problem remains.

新的包结构已随 3.0.0-RC2 发布,并且有一个支持库,因此 v2 和 v3 可以相互通信,而不会出现以前隐藏或明显的编译/运行时问题.这也意味着模块覆盖技巧不再有效,因此您必须手动桥接 AndroidScheduler 或从 Retrofit 中使用的 v2 源进行转换,直到这些(以及许多其他)库开始支持 v3.

The new package structure has been released with 3.0.0-RC2 and there is a support library so that v2 and v3 can talk to each other without hidden or overt compilation/runtime problems from before. This also means that module override tricks no longer work so you have to bridge AndroidSchedulers manually or convert from v2 sources used in Retrofit until these (and many other) libraries start supporting v3.

请参考这个这个

这篇关于RxAndroid 3 主线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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