Android volley enviando datos dos veces


Estoy usando la biblioteca de red Volley en mi aplicación.

El problema es que está enviando datos más de una vez cuando la conexión de red es lenta.

Y Después de buscar en Google este problema, todo lo que puedo encontrar sobre este problema está debajo del punto:

connection.setChunkedStreamingMode(0);

Pero no puedo editar mis clases de volea biblioteca Hurlkstack.

Dice:

El jar de este archivo de clase pertenece a las bibliotecas privadas de Android contenedor que no permite la modificación a archivos adjuntos de origen en las entradas.

¿Qué debo hacer puede alguien ayudarme

Tengo el siguiente código donde debo modificar .

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);
}
Author: Shashikala Chavan, 2015-01-10

5 answers

No hay necesidad de usar connection.setChunkedStreamingMode(0); para evitar volley enviando datos dos veces error. necesita establecer la política de reintento para la solicitud actual:

JsonObjectRequest jsonObjReq = new JsonObjectRequest(...);
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
                       0,
                       DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                       DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
 65
Author: ρяσѕρєя K,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-10 05:39:27

Utilizar el código siguiente después de completar una nueva respuesta.Método ErrorListener () en tu análisis de volea. Espero que sea útil para usted. Me enfrenté al mismo problema y lo resolví con el mismo código.

Código:

jsObjRequest.setRetryPolicy(new DefaultRetryPolicy(
                30000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
 7
Author: Sneha Patel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-09 12:53:50

Esto funcionará

 RetryPolicy mRetryPolicy = new DefaultRetryPolicy(
 0,
 DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
 DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

 request.setRetryPolicy(mRetryPolicy);
 2
Author: Shubham Goel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-12 11:34:26

Prueba esto definitivamente funcionará.

 public <T> void addToRequestQueue(StringRequest req, String tag) {
    req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
    req.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    getRequestQueue().add(req);
}
 1
Author: Hanisha,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-12 08:13:41

Resuelvo este problema para usar este código. Establece getCurrentRetryCount () a devuelve 0 y Usa HurlStack para BaseHttpStack.

RequestQueue requestQueue = Volley.newRequestQueue(NavigationActivity.this, new HurlStack());
    requestQueue.add(stringRequest).setRetryPolicy(new RetryPolicy() {
        @Override
        public int getCurrentTimeout() {
            return 5000;
        }

        @Override
        public int getCurrentRetryCount() {
            return 0; //retry turn off
        }

        @Override
        public void retry(VolleyError error) throws VolleyError {

        }
    });

Espero que esto resuelva el problema.

 0
Author: Mahmudur Rahman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-27 05:04:27