Reputation: 1
In my application, I made a volley request and it is working fine, but when the response does not reach the user, the loader keeps loading and it doesn't stop. What should I do? How do I stop volley requests after 1 min if the response is nothing?
Upvotes: 0
Views: 264
Reputation: 634
you need to implement the ErrorListener and setRetryPolicy method and dismiss the progress in onErrorResponse method
JsonObjectRequest myRequest = new JsonObjectRequest(Method.GET,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressdialog.dismiss()
Log.d(TAG, "V_Error: " + error.getMessage());
/*if (volleyError.getClass().equals(TimeoutError.class)) {
// Show timeout error message
}*/
}
});
myRequest.setRetryPolicy(new DefaultRetryPolicy(
7000,//Socket time out in milies
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Upvotes: 1