androidweb-servicesandroid-volleyrequest-queueing

Error when use RequestQueue in Android?


Here my code:

RequestQueue queue = Volley.newRequestQueue(this);
    JSONObject params = new JSONObject();
    try {
        params.put("email", email);
        params.put("pass", pass);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, "Link Create Account", params, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {               

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });
    queue.add(request);

"Link Create Account" is a link, it working fine with postman (Create only 1 account).

But sometime, I use this code in android, it create 2,3 account with the same details.

I don't know what happen! Any helps. Thank!


Solution

  • Agree with BNK, I have meet the same problem. The reason is for one request, server side spend more time than the client side can wait. For example your client will wait for 1 minutes then retry, but it takes 2 minutes for the server to finish the request, so your client will retry and there will be two result in server.

    And there are two ways to solve the problem, one is to make the client wait for long enough time for the server to finish the request, or speed up your server side; another is like BNK said, make suer Volley will not retry.