Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

Android volley sending data twice

I am using Volley Network Library in my application.

The Issue is that it is sending data more than once when network connection is slow.

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

connection.setChunkedStreamingMode(0);

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

It says:

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);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...