我已经制作了一个简单的util方法,该方法以默认配置返回一个Observable,我遇到的问题是重试,每次重试时我都希望显示一条消息。这是mi代码:
public static <T> Disposable getObservable(
Context contexto,
Observable<Response<T>> serviceObservable,
Consumer<? super Response<T>> handleResponse,
Consumer<? super Throwable> handleException
) {
return serviceObservable.subscribeOn(Schedulers.io())
.retry((retryCount, throwable) -> {
Toast.makeText(contexto, "Retry..." + retryCount, Toast.LENGTH_SHORT).show();
Log.d("TIMEOUT", "Retry..." + retryCount, throwable);
return retryCount < 3 && throwable instanceof SocketTimeoutException;
})
.observeOn(AndroidSchedulers.mainThread())
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(handleResponse, handleException);
}
但是它不起作用,它会重试但不显示消息。
感谢您的帮助!