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
This works for me.
public class MyRetryPolicyWithoutRetry implements RetryPolicy
{
@override
public int getCurrentTimeout()
{
return CONNECTION_TIME_OUT; /200000/
}
@Override
public int getCurrentRetryCount()
{
return 0;
}
@Override
public void retry(VolleyError error) throws VolleyError
{
throw(error);
}
}
To use:
request.setRetryPolicy(new MyRetryPolicyWithoutRetry());
Tried lot of things but in the end nothing helped. Finally, I figured out following combination of changes:
sr.setRetryPolicy(new DefaultRetryPolicy(0,-1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
And in your hurl connection in application class, add this:
httpsURLConnection.setChunkedStreamingMode(0);
This worked smoothly to stop Volley hitting multiple request at server.
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;
}
correcting the android date
fixes my problem unfortunately for testing purpose i have changed my android date and get ssl security error.
I managed to fix this by configuring HttpURLConnection like this:
connection.setChunkedStreamingMode(0);
I started a discussion about this in Volley email list (https://groups.google.com/forum/#!topic/volley-users/8PE9dBbD6iA).
You must set the RetryPolicy to 0 retries and ensure that the timeout is bigger than the server timeout.
setRetryPolicy(new DefaultRetryPolicy("bigger than server timeout",
0,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));