Volley Exception throws BroadCastReceiver

烈酒焚心 提交于 2019-12-22 09:08:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!