How can implement offline caching of json in Android?

后端 未结 3 1472
旧时难觅i
旧时难觅i 2021-02-02 04:42

I am working on a articles application like techcrunch I am parsing data from json. I am parsing title,author and image from json. Articles are displayed in list-view. I want to

3条回答
  •  粉色の甜心
    2021-02-02 05:33

    You must save the json offline. It can be Db or file system. I will prefer to go with Db part.

    The approach is ,every time you get data from server save first in you db then from db you can show it to your UI.

    Inserting in Db can be slow but you can use beginTransaction and other methods which will make it lighting fast.

    Now How can you save data in Db. You have two ways

    • You can parse json first and create the table structure for name,url and other fields then run the query

    • Or store the whole json in Db without parsing .By using GSON or other json parsers this approch will be quite helpful.

提交回复
热议问题