Android Volley double post when have slow request

后端 未结 18 2759
生来不讨喜
生来不讨喜 2020-11-28 04:06

I have a problem with Volley POST request on slow network. Everytime I see BasicNetwork.logSlowRequests in my LogCat, my POST request is executed twice or more

18条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 04:50

    The only way I got the double requests to stop was to set the retry policy retries to -1

    request.setRetryPolicy(new DefaultRetryPolicy(0, -1, 0));
    

    I think this is because the DefaultRetryPolicy's logic for attempts remaining returns true if retryCount is 0 and Max retries is also 0 in the hasAttemptRemaining() method:

    protected boolean hasAttemptRemaining() {
        return this.mCurrentRetryCount <= this.mMaxNumRetries;
    }
    

提交回复
热议问题