I want observable code to run on different thread than main thread. How can I do this, I'm doing like this:
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());
observeOn?Observableto send its notifications to observers on a particular Scheduler by means of theObserveOnoperator. by that you can use yourScheduleror class which implementsSchedulerto observesubscribeOnwill make sure the body of theObservableOnSubscribe.subscribeis executing in one of the IO threads of the IO Scheduler.