Cissmayazz Cissmayazz - 1 year ago 145
Android Question

Change Volley timeout duration

I use the new Volley framework for Android to do a request to my server. But it timeouts before getting the response, although it does respond.

I tried adding this code:

HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, timeoutMs);

of the Volley framework to a different integer (50000), but it still times out before 50 seconds.

Is there a way to change the timeout to a long value?

Answer Source

See Request.setRetryPolicy() and the constructor for DefaultRetryPolicy, e.g.

JsonObjectRequest myRequest = new JsonObjectRequest(Method.GET,
        url, null,
        new Response.Listener<JSONObject>() {

            public void onResponse(JSONObject response) {
                Log.d(TAG, response.toString());
        }, new Response.ErrorListener() {

            public void onErrorResponse(VolleyError error) {
                Log.d(TAG, "Error: " + error.getMessage());

myRequest.setRetryPolicy(new DefaultRetryPolicy(
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download