the_prole the_prole - 6 months ago 61
Android Question

How to change Volley request rate

I'm making multiple requests to Amazon Web Services. I'm getting the 503 error because I'm making too many request too quickly. I want to know how to set the time-out between different requests, not the same ones. I am not looking to set the retry policy. I am also not looking to time-trigger individual requests. I want to time the interval between requests. The reason is that I am looping so quickly and making so many requests, that timing-triggering them is equivalent to submitting them all that the same time. The whole point is to space the requests out evenly.


Since you don't show how you made multiple requests, so I suggest you refer to the following sample, then try applying to your code. Hope it helps!

    protected void onCreate(Bundle savedInstanceState) {

        final RequestQueue queue = Volley.newRequestQueue(this);
        final String url = "";
        final Handler handler = new Handler();
        for (int i = 0; i <= 5; i++) {
            handler.postDelayed(new Runnable() {
                public void run() {
                    StringRequest request = new StringRequest(url, new Response.Listener<String>() {
                        public void onResponse(String response) {
                            Log.i("onResponse", response);                                
                    }, new Response.ErrorListener() {
                        public void onErrorResponse(VolleyError error) {
                            Log.e("onErrorResponse", error.toString());
            }, 2000); // 2000 miliseconds