Android Volley double post when have slow request

后端 未结 18 2687
生来不讨喜
生来不讨喜 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:54

    please increase the setRetryPolicy time.

    request.setRetryPolicy(new DefaultRetryPolicy(
                        30000,
                        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                Volley.newRequestQueue(this).add(equest);
    
    0 讨论(0)
  • 2020-11-28 04:57

    Just setting the Timeout in the RetryPolicy to 0 is too little. After checking the source, you have to actually set the maximum number of retries < 0, as it is checking current <= max...

    I fixed double posting with setting the policy to the following

    new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

    Hope it helps!

    0 讨论(0)
  • 2020-11-28 04:57

    Best Solution:

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(0, 
         DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

    Worked for me.

    0 讨论(0)
  • 2020-11-28 04:58

    Add the following values to your Request object:

    request.setRetryPolicy(new DefaultRetryPolicy(
        DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2,
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    

    Here: request is your object of JsonObjectRequest. Change the value of multiplicator according to the DEFAULT TIMEOUT VALUE in DefaultRetryPolicy class in Volley.

    You can also set the first argument to 0, like below:

    request.setRetryPolicy(new DefaultRetryPolicy(
        0,
        DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    
    0 讨论(0)
  • 2020-11-28 04:58

    I found the solution for the double post, I just set the timeout to 0.

    0 讨论(0)
  • 2020-11-28 04:59

    I found the solution for the multi post bug.

    Change the RetryPolicy. I set the timeout value to 50000ms, worked fine Like this:

      request.setRetryPolicy(
                    new DefaultRetryPolicy(
                            500000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
                    )
            );
    
    0 讨论(0)
提交回复
热议问题