Hi I am getting the Error response for the requests when the network is too slow even though the request is successfully send to the server? Could someone please help me to solve the issue?
Asked
Active
Viewed 1,089 times
0
-
https://stackoverflow.com/questions/17094718/change-volley-timeout-duration – Pavneet_Singh Jul 20 '17 at 15:31
-
use retryPolicy on your stringRequest and control the connection time. – Jul 20 '17 at 15:34
-
Thanks Pavneet. But I do not want to retry – somia Jul 20 '17 at 15:34
-
@Ibrahim, Already he retryPolicy is in lace. – somia Jul 20 '17 at 15:37
3 Answers
0
set value to response time out like
stringRequest.setRetryPolicy(new RetryPolicy() {
@Override
public int getCurrentTimeout() {
// Here goes the new timeout 3 minutes
return 3*60*1000;
}
@Override
public int getCurrentRetryCount() {
// The max number of attempts
return 5;
}
@Override
public void retry(VolleyError error) throws VolleyError {
}
});
You should use above time out before two lines
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);

Enamul Haque
- 4,789
- 1
- 37
- 50
-
I have already added jsonObjRequest.setRetryPolicy(new DefaultRetryPolicy( 50000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); – somia Jul 20 '17 at 15:49
-
-
0
Volley makes more than one call to same API, if the network is slow that gives misleading results. To avoid this scenario add setRetryPolicy flag before adding request to volley queue.
JsonObjectRequest jsonObjReq = new JsonObjectRequest(………….);
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(0,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT.BACKOFF_MULT));
SingletonClass.getInstance.addToRequestQueue(jsonObjReq);
0
Try this code , it lets the api to wait for api response for some particular time period(provided by you)
// time provided to wait for api response
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, cancel_change_api);
}

Android Geek
- 8,956
- 2
- 21
- 35