How can implement offline caching of json in Android?

后端 未结 3 1476
旧时难觅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:13

    I saw you are using Volley. Volley has built-in HTTP Cache mechanism.

    • So the easiest way is to support HTTP cache headers in your backend. It is very easy and it is transparent to the client side. Volley does the hard work. You can find information here

    • If you don't have access to the URL you use, you must use internal database to support your application. ContentProvider API is the best way to do that. And the following library is a great library to construct a database and write to it. https://github.com/TimotheeJeannin/ProviGen

    Basically you need to write every item that you pull from the internet to the database and the ListView should show the items from the database using ContentProvider you have just created. When the user opens the app, show the data from the database and then immediately try to pull the new data from your backend.

提交回复
热议问题