当请求超时,Volley内部会启动重试机制,对超时接口进行多次请求,直到超过此数后,抛出错误信息。
先看看,重试请求是在哪里发出来的。回到BasicNetwork的performRequest方法,看代码后半部分的几个catch捕获,其中有几个地方会发出重试的动作。
catch (SocketTimeoutException var12)
{
attemptRetryOnException("socket", request, new TimeoutError());
}
catch (ConnectTimeoutException var13) {
attemptRetryOnException("connection", request, new TimeoutError());
}
......
catch (IOException var15) {
......
attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
}
然后调用attemptRetryOnException方法,里面 retryPolicy.retry即为重试的发起。
private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError {
RetryPolicy retryPolicy = request.getRetryPolicy();
int oldTimeout = request.getTimeoutMs();
try {
//重试的发起在这里
retryPolicy.retry(exception);
}