How to Cache Parsed JSON for Offline usage

前端 未结 2 1618
走了就别回头了
走了就别回头了 2020-12-30 15:06

I have parsed JSON successfully but now i want to Cache it for offline usage, even internet is not available, and if any new entry comes i want to cache that as well.

<
2条回答
  •  清酒与你
    2020-12-30 16:08

    And what would be the best option to cache data ? SharedPreferences or SQLite database
    

    Which is purely based on the data you received.

    1. If the data is Small,Unstructured data then use Shared Pref.
    2. If the data is Large,Structured data then use SQLite.

    But for store the full data better you can use file concept. Store the string data in your code String data = EntityUtils.toString(entity); the data you have to save to the file.If any changes in the data from the server add that to file.And retrieve the data if internet not present. Get the example code for file operations from the above link.

提交回复
热议问题