Android应用程序在线和离线

时间:2017-01-10 07:09:50

标签: android mysql performance

我必须创建一个Android应用程序,它在Recycler视图中显示一些报告和图像,使用json volley请求它在互联网可用时工作我还需要在互联网视图中显示曾经加载的数据,当互联网不可用时,这里是代码我习惯在互联网可用时选择数据

 JsonObjectRequest jsObjRequest = new JsonObjectRequest
                    (Request.Method.GET, Config.DATA_URL, null, new Response.Listener<JSONObject>() {

                        @Override
                        public void onResponse(JSONObject response) {
                            try {
                                String str = response.toString();

                                                               loading.hide();
                                JSONArray arr =     response.getJSONArray("Stock_Report");


                                parseData(arr);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            // now you have the array. in this array you have the jsonObjects
                            // iterate on this array using a for loop and parse like you did before
                        }
                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub

                        }
                    });

            //Creating request queue
            RequestQueue requestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());

            //Adding request to the queue
            requestQueue.add(jsObjRequest);
        }

请提前帮助我找到更好的解决方案,以便在互联网不可用时显示此数据

0 个答案:

没有答案