SchogunSdz
SchogunSdz

Reputation: 3

ViewRootImpl$CalledFromWrongThreadException rxjava setVisibiltiy through rxjava

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);

Upvotes: 0

Views: 54

Answers (1)

akarnokd
akarnokd

Reputation: 70017

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);

Upvotes: 0

Related Questions