Android排名DefaultRetryPolicy无法按预期工作

Android排名DefaultRetryPolicy无法按预期工作,第1张

概述所以,我有这个Volley PUT请求: private boolean syncCall(JSONObject jsonObject, final VolleyCallback callback) { final ProgressDialog progDailog = new ProgressDialog(context); final Boolean[] s 所以,我有这个Volley PUT请求:
private boolean syncCall(JsONObject JsonObject,final VolleyCallback        callback) {    final ProgressDialog progDailog = new ProgressDialog(context);    final Boolean[] success = {false};    progDailog.setMessage("...");    progDailog.setIndeterminate(false);    progDailog.setProgressstyle(ProgressDialog.STYLE_SPINNER);    progDailog.setCancelable(false);    progDailog.show();    final SharedPreferences prefs = PreferenceManager            .getDefaultSharedPreferences(context);    RequestQueue queue = Volley.newRequestQueue(context,new HurlStack());    final String token = prefs.getString("token",null);    String URL = Constants.getUrlSync();    String param1 = String.valueOf(prefs.getInt("pmp",1));    String param2 = String.valueOf(prefs.getInt("ei",1));    URL = URL.replace("[x]",param1);    URL = URL.replace("[y]",param2);    //pegar ID pmp e IE corretas    JsonObjectRequest JsObjRequest = new JsonObjectRequest(Request            .Method.PUT,URL,JsonObject,new Response.Listener<JsONObject>() {                @OverrIDe                public voID onResponse(JsONObject response) {                    callback.onSuccess(response + "");                    success[0] = true;                    progDailog.dismiss();                }            },new Response.ErrorListener() {                @OverrIDe                public voID onErrorResponse(VolleyError error) {                    callback.onFailure(error);                    tokenFailure(error);                    success[0] = false;                    progDailog.dismiss();                }            }) {        @OverrIDe        public Map<String,String> getheaders() throws                AuthFailureError {            HashMap<String,String> headers = new HashMap<>();            headers.put("Token",token);            return headers;        }    };    int socketTimeout = 30000;    RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,DefaultRetryPolicy.DEFAulT_MAX_RETRIES,DefaultRetryPolicy.DEFAulT_BACKOFF_MulT);    JsObjRequest.setRetryPolicy(policy);    queue.add(JsObjRequest);    return success[0];}

我的问题是我发送了一个非常大的JsON,所以5秒的默认超时是不够的.因此,我尝试将超时增加到30秒,并且使用DefaultRetryPolicy来增加重试次数.

问题是,它在5s内保持计时,甚至不会重试一次!

我是否必须有一个监听器或回调重试?我在使用DefaultRetryPolicy做错了什么?请帮忙,这个问题让我疯狂……

解决方法 您需要使用DefaultRetryPolicy吗?

因为你可以定义自己的.

而不是这个:

RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,DefaultRetryPolicy.DEFAulT_BACKOFF_MulT);

试试这个:

JsObjRequest.setRetryPolicy(new RetryPolicy() {    @OverrIDe        public int getCurrentTimeout() {             // Here goes the new timeout            return mySeconds;         }        @OverrIDe        public int getCurrentRetryCount() {             // The max number of attempts            return myAttempts;         }        @OverrIDe        public voID retry(VolleyError error) throws VolleyError {            // Here you Could check if the retry count has gotten            // To the max number,and if so,send a VolleyError msg            // or something            }    });
总结

以上是内存溢出为你收集整理的Android排名DefaultRetryPolicy无法按预期工作全部内容,希望文章能够帮你解决Android排名DefaultRetryPolicy无法按预期工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1130556.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存