2
votes

I searched a lot from internet to set request timeout of volley. I end up with getting solution of Retry Policy but when researched it does not set timeout it sets the retry time of request but I don't want to retry my request. I want to increase volley request timeout so that a slower network can access data, volley timeout set to 5 sec that means if network does not connect till 5 sec it will throw timeout exception. how can I manage to change time to getting response from server.

my code is

ProjectHistory.requestQueue = Volley.newRequestQueue(mContext);
    int socketTimeout = 30000;//30 seconds - change to what you want
    RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    stringRequest.setRetryPolicy(policy);
    ProjectHistory.requestQueue.add(stringRequest);

I have two question --

(1) Will it retry the request after 30 sec?

(2) how to set request timeout 30 sec so that slower network can load data?

1
yea I had checked this solution but i want to know if there is any method available to override the request time - Abhishek Singh

1 Answers

1
votes

Please check this thread for timeout policy in Volley.

Here in

request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
                0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48, first parameter itself is indicates timeout. Volley will wait for given time and id did not get response then try again if retry is mentioned in policy.

Note: Timeout here mentioned is 2500ms * 48 = 120000ms = 2 mins

Thanks.