我希望可观察代码在不同于主线程的线程上运行。我怎么能这样做,我这样做:
Observable operationObservable = Observable.create(new ObservableOnSubscribe() {
@Override
public void subscribe(ObservableEmitter e) throws Exception {
e.onNext(longRunningOperation());
e.onComplete();
}
})
.subscribeOn(Schedulers.io()) // subscribeOn the I/O thread
.observeOn(AndroidSchedulers.mainThread());