I need to do:
You can use zip
operator to call 2 requests async and save or process their data on response.
For example.
Below are two Observable
Observable responseOneObservable = getRetrofitClient().getDataOne()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
Observable responseTwoObservable = getRetrofitClient().getDataTwo()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
Using zip
operator on above two Observable
as below.
Observable> testDataObservable = Observable.zip(responseOneObservable, responseTwoObservable, new Func2>() {
@Override
public ArrayList call(ResponseOne responseOne, ResponseTwo responseTwo) {
ArrayList testDataList = new ArrayList();
// process data from response responseOne & responseTwo
return testDataList;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber>() {
@Override
public void onNext(ArrayList testDataList) {
}
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted" );
// you can show alert here or do something when completed
}
@Override
public void onError(Throwable t) {
Log.d(TAG, "onError Throwable: " + t.toString() );
}
});