RxAndroid: 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();
}
})
);
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 18 (6 by maintainers)
Well, except for 2.0.0! But yeah they’re otherwise completely independently versioned libraries.
On Tue, Sep 19, 2017 at 3:46 PM Jake Wharton jakewharton@gmail.com wrote:
“don’t always” --> “never”
On Tue, Sep 19, 2017 at 3:46 PM Jason Atwood notifications@github.com wrote:
I’m already using 2.x branch. These are my dependencies.
same error compile “io.reactivex.rxjava2:rxjava:2.1.1” compile ‘io.reactivex.rxjava2:rxandroid:2.0.1’
bugs gone use import io.reactivex.Observable
Go back to
Old Versions
Then to the Newer Version:
Sounds Wierd but it works
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.
This version worked for me
the same error:
compile 'io.reactivex.rxjava2:rxjava:2.1.1' compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
trycompile 'io.reactivex.rxjava2:rxjava:2.1.0
This is working
// RX rxjava2_version = ‘2.0.1’ compile “io.reactivex.rxjava2:rxjava:$rxjava2_version” compile “io.reactivex.rxjava2:rxandroid:$rxjava2_version”
and sample code is
import statements are
Sample Async
Try
Something else could still import RxJava 1 and you use that API. RxJava 1 and 2 are not binary compatible and v2 is not a drop-in replacement. You have to update your imports and change certain class and method names. See the wiki for futher details.