Reputation: 53
Hi I want to implement offline storage in android using cache( like kinvey API)?Can anyone share step wise implementation for same?I searched a lot but don't get much information for Android Cache.
Upvotes: -1
Views: 387
Reputation: 2405
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Cache.Entry entry = cache.get(API);
if (entry != null) {
try {
String data = new String(entry.data, "UTF-8");
JSONObject jobj = new JSONObject(data);
FileWriter file = new FileWriter(cxt.getFilesDir().getPath() + "/" + fileName);
String jsonString = jobj.toString();
file.write(jsonString);
file.flush();
file.close();
// prepareListData(jobj);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
Upvotes: 0