I'm working on a volley POST call from an Android java app that will work onboard a ship where communications are not very good, so there are many fails. The data are sent every 5 minutes to a requestqueue that can accumulate many requests, some of them will fail. I pretend to configure the jsonObjectRequest to insert the failed data into a local database to be synchronize again when ship arrives on port. My question is if there is a way to configure jsonObjectRequest for obtain failed jsonrequest to be executed when an error response is received or when requestqueue produces a timeout?
My code
public void sincronizar_servidor_fast() {
String postUrl = "";
JSONObject json_to_add=new JSONObject();
try{
json_to_add.put("datos",datos_array);
System.out.println("json_to_add");
}catch (JSONException e){}
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, postUrl, json_to_add, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
(int) TimeUnit.SECONDS.toMillis(180), -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(jsonObjectRequest);
if (register_ddbb1) {
if (db != null) {
db.execSQL("");
}
}
}