How to disable Volley request from retrying?

volley retry request
volley repeat request
volley timeout retry
volley slow request
android volley multiple request queues
setretrypolicy in volley
volley and
kotlin volley setretrypolicy

I post a JsonRequest to a server. The server is slow. Volley tends to make multiple calls to the slow server because it didn't get a response from the first request (since my server is slow). Is there any way to disable Volley from retrying a request so that it can receive the first response?

I have tried:

myRequest.setRetryPolicy(new DefaultRetryPolicy(
                TIMEOUT_MS, 
                RETRIES, 
                BACKOFF_MULT)); 

I have replaced TIMEOUT_MS = 0, RETRIES = 0, and even BACKOFF_MULT = 0, but it doesn't work.

Any other suggestions?

The Volley Default Retry Policy is:

/** The default socket timeout in milliseconds */
public static final int DEFAULT_TIMEOUT_MS = 2500;

/** The default number of retries */
public static final int DEFAULT_MAX_RETRIES = 1;

/** The default backoff multiplier */
public static final float DEFAULT_BACKOFF_MULT = 1f;

You can find it in DefaultRetryPolicy.java,

so you can see that volley makes 1 retry request by default.

Try to use smaller TIMEOUT (if you don't want to wait the 2500ms), or bigger than 2500ms to get the answer), but keep the other values, for example:

// Wait 20 seconds and don't retry more than once
myRequest.setRetryPolicy(new DefaultRetryPolicy(
       (int) TimeUnit.SECONDS.toMillis(20),
       DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

Hence, to disable Volley from retrying you will need to do:

myRequest.setRetryPolicy(new DefaultRetryPolicy(
       (int) TimeUnit.SECONDS.toMillis(20), //After the set time elapses the request will timeout
       0,
       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

android - How to disable Volley request from retrying?, Volley tends to make multiple calls to the slow server because it didn't get a response from the first request (since my server is slow). Is there any way to disable  Disable Volley retry request :D. GitHub Gist: instantly share code, notes, and snippets.

Try this,

// remove caching
        jsObjRequest.setShouldCache(false);
        // Wait 30 seconds and don't retry more than once
        jsObjRequest.setRetryPolicy(new DefaultRetryPolicy(0, 0,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

Method call form task

public void callWebService(JSONObject jsonRequest) {

    JsonObjectRequest jsObjRequest = new JsonObjectRequest(
            Request.Method.POST, url + pageurl, jsonRequest,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject jsonObject) {
                    sendResponse(jsonObject);

                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {

                    callBack.onError(error);
                    try {
                        if (progressDialog != null) {
                            progressDialog.dismiss();
                            progressDialog = null;
                        }
                    } catch (Exception e) {
                        Helper.customPrintStackTrace(e);
                    }

                }
            }

    ) {

        @Override
        public String getBodyContentType() {
            return "application/json; charset=utf-8";
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {

            Map<String, String> params = new HashMap<String, String>();

            params.put(WebConfig.WebParams.APIKEY, Helper
                    .getStringValuefromPrefs(context,
                            SharedPreferencesKey.PREF_APIKEY));
            params.put(WebConfig.WebParams.APITOKEN, Helper
                    .getStringValuefromPrefs(context,
                            SharedPreferencesKey.PREF_APITOKEN));

            if (!Helper.getStringValuefromPrefs(context,
                    SharedPreferencesKey.PREF_USERID).equals("")) {

                params.put(WebConfig.WebParams.USER_ID, Helper
                        .getStringValuefromPrefs(context,
                                SharedPreferencesKey.PREF_USERID));

            } else {
                params.put(WebConfig.WebParams.USER_ID, "0");
            }

            return params;
        }

    };

    // remove caching
    jsObjRequest.setShouldCache(false);
    // Wait 30 seconds and don't retry more than once
    jsObjRequest.setRetryPolicy(new DefaultRetryPolicy(0, 0,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    // Access the RequestQueue through your singleton class.
    VolleySingleton.getInstance(context).addToRequestQueue(jsObjRequest);

    if (showDefultProcess) {

        progressDialog.show();
    }

}

Disable Volley retry request :D · GitHub, Disable Volley retry request :D. DisableVolleyRetryPolicy.java. // usage: req.​setRetryPolicy(new VolleyRetryPolicy(DefaultRetryPolicy.​DEFAULT_TIMEOUT_MS  The request's retry policy only applies to failures due to: open socket timeouts, socket opening timeouts, HTTP 401s and HTTP 403s. All other failures are not automatically retried, AFAIK. I think that to retry a 404 with Volley you need to retry it by hand in onErrorResponse.

To stop Volley from retrying a request, simply set the retry policy of the request to a DefaultRetryPolicy with maxNumRetries being 0:

myRequest.setRetryPolicy(new DefaultRetryPolicy(
    DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
    0,  // maxNumRetries = 0 means no retry
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

how to set the retry disable? · Issue #129 · mcxiaoke/android-volley , Hi, I have a project which use volley to post data to server. It work well, but I meet a problem that double request. When asicNetwork. Hi, I have a project which use volley to post data to server. It work well, but I meet a problem that double request. When asicNetwork.logSlowRequests exception happened, request always retry. It lead to the server save the data which th

Using your StringRequest Object or JsonObjectRequest Object or JsonArrayRequest Object call this method.

For example if the object is an instance of StringRequest, here is the method:

stringRequest.setRetryPolicy(new DefaultRetryPolicy(initialTimeoutMs, maxNumRetries,
               backoffMultiplier ));

initialTimeoutMs The initial timeout for the policy.

maxNumRetries The maximum number of retries.

backoffMultiplier Backoff multiplier for the policy.

Below are the parameters which I gave.

stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

First parameter says set InitialTimeout to 10 seconds.

Second parameter says set retry count tries to 0.

Third parameter is default.

Volley time-out retry mechanism detailed, I post a JsonRequest to a server. The server is slow. Volley tends to make multiple calls to the slow server because it didn't get a response from the first request  Name *. Email *. Website. Save my name, email, and website in this browser for the next time I comment. Notify me of follow-up comments by email. Notify me of new posts by email.

Duplicated POST -request with slow request, Volley time-out retry mechanism base usageVolley provides a Retrypolicy determines if a timeout retry is required, and how to stop the timeout retry. Retrypolicy is just the request retry policy interface defined by volley and  In some cases requests to external webservice fail, often with: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect. In that case, more often than not, I want to skip retrying the request (something that Httpclient seems to do automatically) .

Asynchronous HTTP requests in Android using Volley, I need some help Volley is still sending two requests when retry policy is set to 0. this group and stop receiving emails from it, send an email to volley-users. But anyway - even you disable request retrying for POST, HTTP by default is not "reliable" for this, you also need to implement some logic on your server to detect duplicate requests. You could send one single POST request to the server and it would be received and processed by the server but the answer would never get back to you (connection failed).

Customize volley default retry Policy & Cache timeout, Installing and using Volley as a library project; Using Request Queue; Making asynchronous JSON and String HTTP requests; Cancelling requests; Retrying  By default, Volley set timeout equally for both setConnectionTimeout() and setReadTimeout() with the value from RetryPolicy. In my case, Volley throws timeout exception for large data chunk see: com.android.volley.toolbox.HurlStack.openConnection(). My solution is create a class which extends HttpStack with my own setReadTimeout() policy.

Comments
  • How do I make DEFAULT_MAX_RETRIES = 0 for all requests? any possibilities?
  • @BalaVishnu You don't have to change the default value. All you have to do is to use my code above, and set the second parameter to 0.
  • Oh K..Thank you, but was wondering if any global setting can be made for this so that we need not give this line again and again in all requests.
  • @BalaVishnu Ha, so open the DefaultRetryPolicy volley class and change the DEFAULT_MAX_RETRIES to 0 (the default is 1)
  • myRequest.setRetryPolicy(new DefaultRetryPolicy( 2500, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); won't retry at all ?