1

As the title implies, my Volley request returns data twice and I tried all the solutions I can find including this and this

This is my code just in case I did something else wrong.

JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(
                Request.Method.GET,
                url,
                null,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        dataCallback.onSuccess(response);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        dataCallback.onError(error);
                    }
                }
        ) {
            @Override
            public Map<String, String> getHeaders() {

                Map<String, String> headers = new HashMap<>();
                headers.put("Content-Type", "application/json");
                headers.put("Authorization", "Bearer " + access_token);
                headers.put("trakt-api-version", "2");
                headers.put("trakt-api-key", client_id);
                return headers;
            }
        };
        jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
                0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        AppController.getInstance().addToRequestQueue(jsonArrayRequest);
    } catch (Exception e) {
        e.printStackTrace();
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Tony
  • 21
  • 5

1 Answers1

0

You have implement retry policy in your code, that give you twice response

 //try after comment or remove below line
  jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(
            0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Dharmender Manral
  • 1,504
  • 1
  • 6
  • 7