如何在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