Change Volley timeout duration

前端 未结 9 760
梦如初夏
梦如初夏 2020-11-22 14:55

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

9条回答
  •  一个人的身影
    2020-11-22 15:19

    Just to contribute with my approach. As already answered, RetryPolicy is the way to go. But if you need a policy different the than default for all your requests, you can set it in a base Request class, so you don't need to set the policy for all the instances of your requests.

    Something like this:

    public class BaseRequest extends Request {
    
        public BaseRequest(int method, String url, Response.ErrorListener listener) {
            super(method, url, listener);
            setRetryPolicy(getMyOwnDefaultRetryPolicy());
        }
    }
    

    In my case I have a GsonRequest which extends from this BaseRequest, so I don't run the risk of forgetting to set the policy for an specific request and you can still override it if some specific request requires to.

提交回复
热议问题