title: How can implement offline caching of json in Android?
body: <p>I am working on a articles application like techcrunch I am parsing data from json.
  I am parsing title,author and image from json.
  Articles are displayed in list-view.
  I want to do offline caching means when there is no internet user can read the articles.</p>
  
  <p>Here is my code-</p>
  
  <pre><code>public class OneFragment extends Fragment {
  
  public OneFragment(){}
  private static final String TAG = OneFragment.class.getSimpleName();
  
  // Movies json url
  private static String URL = "http://url";
  private ProgressDialog pDialog;
  private List&lt;Movie&gt; movieList = new ArrayList&lt;Movie&gt;();
  private ListView listView;
  private CustomListAdapter adapter;
  int current_page = 0;
  int mPreLast;
  SwipeRefreshLayout swipeView;
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      final View rootView = inflater.inflate(R.layout.swip, container, false);
      swipeView = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe);
      swipeView.setColorScheme(android.R.color.holo_blue_dark, android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_green_dark);
      pDialog = new ProgressDialog(getActivity());
      pDialog.setMessage("Loading...");
      pDialog.show();
      pDialog.setCancelable(false);
  
      swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  
          @Override
          public void onRefresh() {
              // TODO Auto-generated method stub
              swipeView.setRefreshing(true);
              Log.d("Swipe", "Refreshing Number");
              ( new Handler()).postDelayed(new Runnable() {
  
                  @Override
                  public void run() {
                      // TODO Auto-generated method stub
                      swipeView.setRefreshing(false);
                      onStart();
                  }
              }, 3000);
          }
      });
  
      listView = (ListView) rootView.findViewById(R.id.list49);
      listView.setOnScrollListener(new AbsListView.OnScrollListener()
      {
          @Override
          public void onScrollStateChanged(AbsListView absListView, int i)
          {
  
          }
  
          @Override
          public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
          {
              int lastItem = firstVisibleItem + visibleItemCount;
                 if(lastItem == totalItemCount){
                     if (mPreLast != lastItem)
                     {
                          mPreLast = lastItem;                           
                          pDialog = new ProgressDialog(getActivity());
                          pDialog.setMessage("Loading more articles...");
                          pDialog.show();
                          //pDialog.setCancelable(false);
                          onStart(); 
                     }
              }
          }
      });
  
      listView.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt;  adapterView, View view, int Position,
                  long offset)  { 
              // TODO Auto-generated method stub
              Movie item = (Movie) adapter.getItem(Position);             
              Intent intent = new Intent(rootView.getContext(), SingleArticle.class);
              single.title = item.getTitle();
              single.author = item.getAuthor();
  
              startActivity(intent);
  
  
              }        
          });
      //pDialog = new ProgressDialog(this);
      // Showing progress dialog before making http request
  
      return rootView;
  }
  
  @Override
  public void onStart(){
      super.onStart();
      // calling adapter changes here, just
      // to avoid getactivity()null
      // increment current page
       current_page += 1;
      // Next page request
      URL = "http://url" + current_page;
      //adapter = new CustomListAdapter(this, movieList);
      int currentPosition = listView.getFirstVisiblePosition();
      adapter = new CustomListAdapter(getActivity(), movieList);
      listView.setAdapter(adapter);
      listView.setSelectionFromTop(currentPosition + 1, 0);
      // changing action bar color
      //getActivity().getActionBar().setBackground(
              //new ColorDrawable(Color.parseColor("#1b1b1b")));
  
      // Creating volley request obj
      JsonArrayRequest movieReq = new JsonArrayRequest(URL,
              new Response.Listener&lt;JSONArray&gt;() {
  
                  @Override
                  public void onResponse(JSONArray response) {
  
                      Log.d(TAG, response.toString());
                      hidePDialog();
  
                      // Parsing json
                      for (int i = 0; i &lt; response.length(); i++) {
                          try {
  
                              JSONObject obj = response.getJSONObject(i);
                              Movie movie = new Movie();
                              movie.setTitle(obj.getString("title"));
                              movie.setAuthor(obj.getString("author"));
                              // adding movie to movies array
                              movieList.add(movie);
  
  
  
  
                              adapter.notifyDataSetChanged();
  
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
                      }                       
                  }
              },new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
                      VolleyLog.d(TAG, "Error: " + error.getMessage());
                      new AlertDialog.Builder(getActivity())
                      .setTitle("No Connectivity ")
                      .setMessage("Please check your internet connectivity!")
                      .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int which) { 
                              // continue with delete
                          }
                       })
                      //.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                          //public void onClick(DialogInterface dialog, int which) { 
                              // do nothing
                          //}
                       //})
                      .setIcon(android.R.drawable.ic_dialog_alert)
                       .show();
                      hidePDialog();
  
                  }
              });
      AppController.getInstance().addToRequestQueue(movieReq);    
      //listView.setAdapter(adapter);
  
  }
  
  private View getActionBar() {
      // TODO Auto-generated method stub
      return null;
  }
  
  @Override
  public void onDestroy() {
  super.onDestroy();
  hidePDialog();
  }
  
  private void hidePDialog() {
  if (pDialog != null) {
      pDialog.dismiss();
      pDialog = null;
  }
  }
  }
  </code></pre>