How to prevent Volley request from retrying?

后端 未结 4 939
春和景丽
春和景丽 2020-12-13 18:54

I post a JsonRequest to a server. The server is slow and Volley tends to make multiple calls to the slow server because it didn\'t get a response from the first request (sin

4条回答
  •  忘掉有多难
    2020-12-13 19:24

    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.

提交回复
热议问题