This page says that we can register a Listener to a volley request for handling errors: https://developer.android.com/training/volley/simple
But it doesn't mention what kind of errors trigger this listener. Volley javadoc doesn't say anything about it either.
Specifically, will this listener be executed if a network error occurs. I'm asking this because I've encountered an android code of the following form:
private void method() {
String URL = "";
final int[] status_code = new int[1];
StringRequest request = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (status_code[0] == 200) {
// do something
} else {
// display toast
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// display toast
}
}) {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
status_code[0] = response.statusCode;
return super.parseNetworkResponse(response);
}
};
// add request to queue
}
This code seems to suggest that the registered ErrorListener isn't called for network errors.
What are the conditions which cause the ErrorListener registered to a Volley request to be called
from What causes the ErrorListener registered to a volley request to be triggered?
No comments:
Post a Comment