If you need to connect the answers of these requests, the operator concat is quite suitable concat Here is a small demonstration
final String[] aStrings = {"A1", "A2", "A3", "A4"}; final String[] bStrings = {"B1", "B2", "B3"}; final Observable<String> aObservable = Observable.fromArray(aStrings); final Observable<String> bObservable = Observable.fromArray(bStrings); Observable.concat(aObservable, bObservable) .subscribe(getObserver());
At the output, we get the data stream of the "A1", "A2", "A3", "A4" and then "B1", "B2", "B3"
You can also use the operator merge
Observable.merge(aObservable, bObservable) .subscribe(getObserver());
then the output is a stream of data
"A1", "B1", "A2", "A3", "A4", "B2", "B3"
or zip
Observable<String> stringObservable1 = Observable.just("Hello", "World"); Observable<String> stringObservable2 = Observable.just("Bye", "Friends"); Observable.zip(stringObservable1, stringObservable2, new BiFunction<String, String, String>() { @Override public String apply(@NonNull String s, @NonNull String s2) throws Exception { return s + " - " + s2; } }).subscribe(new Consumer<String>() { @Override public void accept(String s) throws Exception { System.out.println(s); } });
get out
Hello - Bye World - Friends
I would not write this purely android threads for this resource I advise you to use rxJava.