问题
I am developing my project using volley library.
When I parse data it throws error sometime if any network problem or server side error, I want to display this error message using toast but I can't handle this and not show any toast on error of volley. So I want to manage this problem using broadcast receiver. If it possible then please give me any suggestion or solution for solve this problem. My code of display toast on error using volley is:
mRequestQueue = Volley.newRequestQueue(context);
JsonObjectRequest jr = new JsonObjectRequest(Request.Method.POST, url, jsonReq,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("response", response.toString());
dataObj.loadData(response);
if(flag){
context.startActivity(intent);
}
}
},
new Response.ErrorListener() {
@SuppressLint("ShowToast")
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, error.toString(), Toast.LENGTH_LONG);
Log.e("Json parse error", error.toString());
}
});
//RequestQueue mRequestQueue = Volley.newRequestQueue(this);
mRequestQueue.add(jr);
回答1:
I think you forgot to show toast
Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show();
Trying to turn on Android Lint as it will you a lot including this case.
来源:https://stackoverflow.com/questions/17826914/volley-exception-throws-broadcastreceiver