Retrofit2+Rxjava2 使用Observable.mergeArray()或merage()中间请求出错导致后续请求中断解决

 代码如下:当进行多个请求时中间请求返回数据错误或数据错误时,导致后续的请求无法进行

 public Observable[] getAllObservable() {
        Observable[] observables = new Observable[9];

        observables[0] = NetClient.getCJXXBean(deviceID)
                .subscribeOn(AndroidSchedulers.mainThread())
                .compose(this.bindToLifecycle());

        observables[1] = NetClient.getWZXXBean(deviceID)
                .subscribeOn(AndroidSchedulers.mainThread())
                .compose(this.bindToLifecycle());
}
Observable.mergeArray(getAllObservable())
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(bean -> {
            if (bean != null && bean.getCode() == 1) {
                switchDataType(bean);
            }
        }, new ExceptionImp(this), new CompleteImp(this).setCallBack(new CompleteImp.CallBack() {
            @Override
            public void callback() {
                CQCBDeviceInfoActivity.this.onReFreshSuccess();
            }
        }));

解决方法:使用mergeDelayError操作符

使用方法可见:RxJava合并Observable——merge和mergeDelayError操作符【 清风飞阳】

你可能感兴趣的:(bug解决,android)