Skip to content

Volley什么时候重发请求 #1

@LNeway

Description

@LNeway

不知道楼主现在是否记得请求重发这一块的逻辑,看源码找了半天都没有找到

/** * Prepares for the next retry by applying a backoff to the timeout. * @param error The error code of the last attempt. */ @Override public void retry(VolleyError error) throws VolleyError { mCurrentRetryCount++; mCurrentTimeoutMs += (mCurrentTimeoutMs * mBackoffMultiplier); if (!hasAttemptRemaining()) { throw error; } }

上面这块代码是 NetworkDispatcher 中 run方法的实现

下面是DefaultRetryPolicy里面当中的代码,但是在这个代码中没有看到它把请求添加到请求队列当中。

request = null; try { // Take a request from the queue. request = mQueue.take(); } catch (InterruptedException e) { // We may have been interrupted because it was time to quit. if (mQuit) { return; } continue; }

这个请求在真正发送之前就从队列里面拿出来了,但是在重试的时候又没有放进去。

所以请教一下楼主知不知道Volley请求重发的核心代码,谢谢!

需要重发的请求是否放到了请求的队列当中,如果放进去了是在哪里放进去的,如果没有放到请求队列当中,那么这个重发的请求又是如何实现的?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions