This is my JSON code. I want to cache JSON data from URL for the first time and second time it will be work without internet.How and where have to use the volley cache tool, and how to access the saved file??
StringRequest stringRequest = new StringRequest(Request.Method.GET, Constants.URL_CONTACTS, new Response.Listener<String>() {
@Override
public void onResponse(final String response) {
new Thread(new Runnable() {
@Override
public void run() {
try{
JSONObject jsonObject = new JSONObject(response);
if(jsonObject.has(Constants.TAG_EXAM)) {
JSONArray examArray = jsonObject.getJSONArray(Constants.TAG_EXAM);
for(int i = 0; i < examArray.length(); i++) {
// get all array from JSON object
JSONObject seat = examArray.getJSONObject(i);
}
}
handler.sendEmptyMessage(1);
} catch (JSONException e) {
handler.sendEmptyMessage(2);
e.printStackTrace();
} catch (NullPointerException e) {
handler.sendEmptyMessage(3);
e.printStackTrace();
}
}
}).start();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}``
})`