I use RxJava and RxAndroid, and I want to combine the two observables, but between them I need to update the interface, so I have to execute the code in the main thread before I reach the subscriber.
One solution, and not flatmapping (is it an accepted term?) Two observables, would call the next observable in the subscriber immediately after updating the user interface, but I feel that there should be a more elegant solution, for example:
myObservable .map(new Func1<Object, Object>() { @Override public Object call(Object object) { return object; } }) .flatMap(new Func1<Object, Observable<OtherObject>>() { @Override public Observable<OtherObject> call(Object o) { return new MyOtherObservable(o); } }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread());
Of course, probably the map is not the operator that I need to use here. So, is there an operator, or a better way to achieve this? Or am I missing the question of how observables should work?
android rx-java rx-android
Pnikosis
source share