Hi Everyone currently I have a problem with threads in RXJava. I wanna set visible through rxjava but android throw me a this exception
"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);
You applied delay
after observeOn
so the flow was switched away from the UI thread. Drop observeOn
and reorder the flow as follows:
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);