Android 截击两次发送数据 [英] Android volley sending data twice

查看:26
本文介绍了Android 截击两次发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了 Volley 网络库.

I am using Volley Network Library in my application.

问题在于,当网络连接速度较慢时,它会多次发送数据.

在我谷歌这个问题之后,我能找到的关于这个问题的所有内容如下:

And After I Google this issue, all i can find about this issue is below point:

connection.setChunkedStreamingMode(0);

但我无法编辑我的 volley 库 Hurlkstack 类.

But I am not able to edit my volley library Hurlkstack classes.

它说:

此类文件的jar属于容器android私有库,不允许修改其条目上的源附件.

The jar of this class file belong to container android Private libraries which does not allow modification to source attachments on it entries.

我该怎么办,谁能帮帮我

What should i do can some one help me

我有以下代码我应该在哪里修改.

i have the following code where should i modify .

private void makeJsonObjectRequest() {
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
            "http://example.com/***.php", obj, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        response.getString("success");
                        } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                }
            });

    AppController.getInstance().addToRequestQueue(jsonObjReq);
}

推荐答案

无需使用 connection.setChunkedStreamingMode(0); 来避免 连续发送两次数据 错误.您需要为当前请求设置重试策略:

No need to use connection.setChunkedStreamingMode(0); to avoid volley sending data twice bug. you need to set retry policy for current request :

JsonObjectRequest jsonObjReq = new JsonObjectRequest(...);
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
                       0,
                       DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

这篇关于Android 截击两次发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆