javaandroidandroid-volleyrequest-timed-outretrypolicy

Volley request retry policy doesn't consider timeout


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!!!


Solution

  • 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.