ViewRootImpl$CalledFromWrongThreadException rxjava setVisibiltiy 通过 rxjava
ViewRootImpl$CalledFromWrongThreadException rxjava setVisibiltiy through rxjava
大家好,目前我在 RXJava 中遇到线程问题。我想通过 rxjava 设置可见但 android 抛出一个异常
"ViewRootImpl$CalledFromWrongThreadException"
Disposable disposable = Single.concat(
getClearStorageObservable()
.doOnError(Timber::e)
.onErrorResumeNext(Single.just(false)),
getDownloadObservable())
.subscribeOn(schedulers().io())
.observeOn(schedulers().ui())
.delay(DELAY_VALUE,TimeUnit.SECONDS)
.timeout(5, TimeUnit.SECONDS)
.subscribe(status -> hideErrorInformation(),
error -> showErrorInformation()
);
disposables().add(disposable);
您在 observeOn
之后应用了 delay
,因此流从 UI 线程切换开。删除 observeOn
并按如下方式重新排序流程:
Disposable disposable = Single.concat(
getClearStorageObservable()
.doOnError(Timber::e)
.onErrorResumeNext(Single.just(false)),
getDownloadObservable())
.subscribeOn(schedulers().io())
.timeout(5, TimeUnit.SECONDS, schedulers().ui())
.delay(DELAY_VALUE, TimeUnit.SECONDS, schedulers().ui())
.subscribe(status -> hideErrorInformation(),
error -> showErrorInformation()
);
disposables().add(disposable);
大家好,目前我在 RXJava 中遇到线程问题。我想通过 rxjava 设置可见但 android 抛出一个异常
"ViewRootImpl$CalledFromWrongThreadException"
Disposable disposable = Single.concat(
getClearStorageObservable()
.doOnError(Timber::e)
.onErrorResumeNext(Single.just(false)),
getDownloadObservable())
.subscribeOn(schedulers().io())
.observeOn(schedulers().ui())
.delay(DELAY_VALUE,TimeUnit.SECONDS)
.timeout(5, TimeUnit.SECONDS)
.subscribe(status -> hideErrorInformation(),
error -> showErrorInformation()
);
disposables().add(disposable);
您在 observeOn
之后应用了 delay
,因此流从 UI 线程切换开。删除 observeOn
并按如下方式重新排序流程:
Disposable disposable = Single.concat(
getClearStorageObservable()
.doOnError(Timber::e)
.onErrorResumeNext(Single.just(false)),
getDownloadObservable())
.subscribeOn(schedulers().io())
.timeout(5, TimeUnit.SECONDS, schedulers().ui())
.delay(DELAY_VALUE, TimeUnit.SECONDS, schedulers().ui())
.subscribe(status -> hideErrorInformation(),
error -> showErrorInformation()
);
disposables().add(disposable);