如何在Android中的rxJava出现网络错误时进行重试网络调用。在RxJava中重试网络呼叫
这里是我的rxJave代码:
RxTextView.textChanges(searchInput)
.debounce(500, TimeUnit.MILLISECONDS)
.map(CharSequence::toString)
.filter(s -> !s.isEmpty())
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(Schedulers.io())
.switchMap(query -> getTypedPlaces(query))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(results -> showResult(results));
它工作得很好,但我需要重新尝试网络请求时连接中断。
您试过['retry()'](http://reactivex.io/documentation/operators/retry.html)运算符吗? – EpicPandaForce
为了首先使用retry(),我必须检测网络连接。如果有网络错误,我该如何检测网络连接?如何重新尝试 –
您可以看看['retryWhen()'](http:// reactivex。 io/documentation/operators/retry.html#collapseRxJava) – EpicPandaForce