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
It's a problem of timeout error The request is execute twice so you have a double value
Try to increase the timeout error request with this code :
request.setRetryPolicy(new DefaultRetryPolicy(
DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Volley request policy only one time request to avoid duplicate post
I tried this solution, but does not working
//...........solution 01
jsonObjectRequest.retryPolicy = DefaultRetryPolicy(
120000,
0,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
or
//...........solution 02
jsonObjectRequest.retryPolicy = DefaultRetryPolicy(
0,
-1,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest)
Full Source Code: https://androidkeynotes.blogspot.com/2020/02/volley.html
just maxNumRetries = 0 no work.
set TIMEOUT_MS 20000.
request.setRetryPolicy(new DefaultRetryPolicy(20000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
I am able to solve this issue by two ways.
First is changed the RetryPolicy.
Simply set the timeout value to double of the default timeout. Worked fine. You can also try other values.
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Another way is by setting connection.setChunkedStreamingMode(0); in openConnection method HurlStack class.
I am creating my RequestQueue like this requestQueue = Volley.newRequestQueue(context, new HurlStack());
Hope it helps :)
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
This worked for me.
I asked a similar question here:
Android Volley makes 2 requests to the server when retry policy is set to 0
I managed to solve this issue by setting the keep-alive property to false inside Android, e.g.:
System.setProperty("http.keepAlive", "false")
I added this line of code inside the class where I import requestqueue and make the requests.
Also, check if you server has the keep-alive header.
This post helped get to the solution.