android - rxjava run multiple observable sequence with condition -


i have 4 observable, , want call sequence

observable1 //return boolean -> observable2 // if(observable1 result == true) { call observable3 } else { call observable4 } -> observable3 // call observable4 -> observable4 -> subscribe(); 

i tried it, when observable1 result false oncompleted called

observable     .fromcallable(new callable<boolean>() {         @override         public boolean call() throws exception {             return false;         }     })     .flatmap(new func1<boolean, observable<string>>() {         @override         public observable<string> call(boolean aboolean) {             if(aboolean) {                 return observable.just("to observable2");             }             return null; // observable 3         }     })     .flatmap(new func1<string, observable<integer>>() {         @override         public observable<integer> call(string s) {             return observable.just(1);  //to observable3         }     })     .flatmap(new func1<integer, observable<boolean>>() {         @override         public observable<boolean> call(integer integer) {             return observable.just(true); //success         }     })     .subscribe(new subscriber<boolean>() {         @override         public void oncompleted() {             log.e("tag", "oncompleted");         }          @override         public void onerror(throwable e) {             log.e("tag", "onerror", e);         }          @override         public void onnext(boolean bool) {             log.e("tag", "onnext");         }     }); 

how can achieve ? thanks

there many ways of doing this. proposed based on first pseudocode offering.

observable.just(boolean)   .flatmap( boolean -> if (boolean) return observable3                         else return observable.just(boolean))   .flatmap(boolean -> observable4)   .subscribe() 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -