Home » Android » java – Volley request retry policy doesn't consider timeout

java – Volley request retry policy doesn't consider timeout

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’ve set 1500 as initialTimeoutMs in DefaultRetryPolicy as below but it doesn’t consider the timeout:

request.setRetryPolicy(new DefaultRetryPolicy(1500
        , DefaultRetryPolicy.DEFAULT_MAX_RETRIES
        , DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

I disconnected the WiFi on my device to test it’s timeout and I saw these times in the Logcat:

2019-12-16 14:28:15.892 I/MyClass: request sent
2019-12-16 14:28:35.930 I/MyClass: request caught onError

It took more than 20 seconds while I expected to catch either onResponse or onError after 1.5 seconds!!!

How to&Answers:

According to your configure. Your timeout should be 3 secs.
Referring to http://prasadthangavel.blogspot.com/2013/12/why-volley-android-has-provided-two.html

I think you should make DEFAULT_BACKOFF_MULT zero.

Answer:

Use 5 sec because 15 sec it much more for giving in timeout..

int TIME_OUT = 500; //use 5 sec it will work fine with it..

request.setRetryPolicy(new DefaultRetryPolicy(
    TIME_OUT, 
    DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));