Search code examples
androiddata-synchronization

how to handle updates from the server - sync


I have a JSON response,

Basically a list of categories

[{event_cat_id: "1", event_cat_name: "Sport" 
}, { event_cat_id: "25", event_cat_name: "Cinema" }]

using the ID, I query the server for a list of events.

All the events sent back are stored in a local DB.

My problem is that the list of categories can change, I want to know what is the best of way of checking for updates on the server.

I could send a request every time the view is clicked? Would that affect the user experience?

Building on android


Solution

  • On server side keep timestamp of last update for each record and property if record is available
    ex:

    id: 25, name: Cinema, available: 1, timestamp: 1342777317
    
    1. Get server current time
    2. Get data from server modified since last synchronization time
    3. Parse and store data in local database
    4. Write server time from 1. point as last synchronization time

    It's easy to query data on server modified since a timestamp. At first synchronization last synchronization time is simply 0.
    You can't delete records on server side, you can set them as unavailable: available: 0