Nam Nguyen
Nam Nguyen

Reputation: 327

Android - How to cache Json using SQLite

My application should work not only in online but also in offline mode. When my app have internet connection, it will download data (parse from Json) and save to SQLite database. If I turn off internet, it will get data from SQLite to display. My problems are how I know when data update or have new data from server. I want update current records and add new records when data change.

Ex:

First load - Load 50 records >>> save to SQLite

Second load - Load 30 records (20 current records change & 15 new records)

Total - 65 records in SQLite

Thanks for any help

Upvotes: 1

Views: 2034

Answers (1)

Andy Gaskell
Andy Gaskell

Reputation: 31761

This sounds like more of a server API issue than anything. Your app needs to know when it went offline (we'll call this lastCommTime). When the application is back online you need to query the server for 1) records that have been updated since lastCommTime and 2) records that were inserted since lastCommTime.

How you handle this on the backend is a design decision you'll have to make. Many web application frameworks have created_at and updated_at fields.

Upvotes: 2

Related Questions