I realize that I am using subscribeOn()/observeOn() on the MainThread. What are the set of options I can pass into subscribeOn()? What are the set of options I can pass into
You should call Observable.unsubscribeOn(Schedulers.io())
, retrofit
will unsubscribe at the end of a http-request.
In RxJavaCallAdapterFactory
of retrofit-rxjava-adapter
it actions like this.
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
But when subscriber
is a SafeSubscriber
, it'll call unsubscribe
finally.
I have this issue in my app.
Full code:
o.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.unsubscribeOn(Schedulers.io());
Rewrite the last part of your code to:
service.getOneTestRx()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<MyTest>() {
@Override
public void onCompleted() {
Log.d(TAG, "[onCompleted] ");
}
@Override
public void onError(Throwable t) {
Log.d(TAG, "[onError] ");
t.printStackTrace();
}
@Override
public void onNext(MyTest m) {
Log.d(TAG, "[onNext] " + m.toString());
}
});
Important note from @akarnokd:
Worth mentioning that one needs to chain the calls as here because Observable is not the builder pattern (where you modify the settings of an existing object)