How to run 2 queries sequentially in a Android RxJava Observable?

后端 未结 3 740
情歌与酒
情歌与酒 2021-01-04 04:59

I want to run 2 asynchronous tasks, one followed by the other (sequentially). I have read something about ZIP or Flat, but I didn\'t understand it very well...

My pu

3条回答
  •  伪装坚强ぢ
    2021-01-04 06:02

    The operator to do that would be merge, see http://reactivex.io/documentation/operators/merge.html.

    My approach would be to create two observables, let's say observableLocal and observableRemote, and merge the output:

    Observable observableLocal = Observable.create(...)
    Observable observableRemote = Observable.create(...)
    Observable.merge(observableLocal, observableRemote)
              .subscribe(subscriber)
    
    
    

    If you want to make sure that remote is run after local, you can use concat.

    提交回复
    热议问题