如何在android中使用缓存实现离线存储?

时间:2016-08-08 10:04:04

标签: android caching offline-storage

您好我想使用缓存(如kinvey API)在Android中实现离线存储?任何人都可以共享逐步实现吗?我搜索了很多但没有获得Android缓存的大量信息。

1 个答案:

答案 0 :(得分:0)

   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();
                }
            }
相关问题