I am new to RxJava and I think I am probably overlooking something very basic. So I have created an Observable
that performs a long running I/O task like this. Now I want to make sure that subscriber receives its result on Android UI Thread:
Observable.create(new ObservableOnSubscribe<Device>() {
@Override
public void subscribe(@io.reactivex.annotations.NonNull final ObservableEmitter<Device> e) throws Exception {
//Long running task
}
}).subscribeOn(Schedulers.io())
As you can see, I have performed the long running task on Schedulers.io()
. How do I switch back to Android UI thread?
You have to perform observeOn(AndroidSchedulers.mainThread())
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With