SolvedRxAndroid Can't use AndroidSchedulers.mainThread() after migrating to RxJava2?

After migrating to RxJava2. observeOn doesn't accept AndroidSchedulers.
Is there a alternate in Schedulers for AndroidSchedulers.mainThread() or how should i solve this issue ?

OLD versions
RxAndroid - 1.2.1
RxJava - 1.1.6

Migrated Versions
RxAndroid - 2.0.1
RxJava - 2.0.3

 rxHelper.manageSubscription(
                mDataManager.getProducts()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new SingleSubscriber<List<Items>>() {
                    @Override
                    public void onSuccess(List<Items> products) {
                        getView().hideProgress();
                        if (!products.isEmpty()) {
                            getView().showText(String.valueOf(products.get(0).getName()));
                            getView().showItems(products);
                        } else {
                            getView().showEmpty();
                        }
                    }

                    @Override
                    public void onError(Throwable error) {
                        Timber.e(error, "There was an error retrieving the products");
                        getView().hideProgress();
                        getView().showError();
                    }
                })
        );
19 Answers

✔️Accepted Answer

Other Answers:

I'm already using 2.x branch. These are my dependencies.

    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.3'

rx

Yep. You're importing the wrong class as Artem said. Correct the import or use the fully qualified name to point at the 2.x version of this class.

Go back to

Old Versions

compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'

Then to the Newer Version:

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.1'

Sounds Wierd but it works