I want to give to my user a much better offline user experience, therefore, I want to build a Service
which stores all POST
, DELETE
,
you maybe do a networking validation method :
1. check the network connection
YES:
a) make the volley request
b) parse the adapter from volley request
c) and save the json into a private file
NO:
a) read the private file
b) make the adapter from json file downloaded.
********************** for example
if(isconnect){
JsonArrayRequest Req = new JsonArrayRequest(url,
new Response.Listener() {
public void onResponse(JSONArray response) {
//this the request of your http request
Log.d(TAG, response.toString());
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
......adapter etc etc
}
adapter.notifyDataSetChanged();
//here write the httprequest (json file) in local memory
try {
String textjson= response.toString();
fos = context.openFileOutput("request.json",MODE_PRIVATE);
fos.write(textjson.getBytes("ISO-8859-1")); //encode
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
swipeRefreshLayout.setRefreshing(false);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// VolleyLog.d(TAG, "Error: " + error.getMessage());
} }); AppController.getInstance().addToRequestQueue(movieReq);
}
else{
//noconnection();
in the noconnection method u can parse the listview/recyclerview from json file to make the offline mode }
}else{
//parse the listview/recyclerview from local file. }