Volley RequestQueue: retry after noConnectionError

I am trying to implement a simple asynchronous HTTP request by pushing some data to the server and working with the response. But once the smartphone goes out of network access, and StringRequest stops with noConnectionError. The request seems complete and the retry rules are not applied (retry fails, regardless of whether I add my own retryrules or not).

StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://myurl/test.php",
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                // Do something with the response
                Toast.makeText(context, response, Toast.LENGTH_SHORT).show();
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                // Handle error
                Toast.makeText(context, error.toString(), Toast.LENGTH_SHORT).show();
            }
        }) {
    @Override
    protected Map<String, String> getParams() {
        return params;
    }

    @Override
    protected VolleyError parseNetworkError(VolleyError volleyError) {
        Log.d("DEBUG", "parseNetworkError");
        return super.parseNetworkError(volleyError);
    }

    @Override
    public void deliverError(final VolleyError error) {
        Log.d("DEBUG", "deliverError");
    }
};
stringRequest.setRetryPolicy(new MyRetryPolicy(20 * 1000, 5, 1.0f));

MyRetryPolicy:

@Override
public void retry(VolleyError error) throws VolleyError {
    Log.d("DEBUG", ""+error);
    // This is never getting called on NoConnectionError
}

Logging tells me "parseNetworkError" and then "deliverError".

But I'm not sure how to tell him to stay in line until the network returns and the request can be transmitted through the server.

Does anyone know how to make him wait for a positive response and repeat it until received?

HTTP-, ?

+4

All Articles