Question

I have an Android app that needs to receive some data from the webserver. I already got everything working, my question is.. What's the best way to synchronize data from the webserver if I'm always adding some data to it's remote database through a HTML form?

I thought of putting a timestamp, then I can receive the data with the timestamp, I would be able to compare the timestamps with each data entry from my Android app database, then, update or add the information to my local database.

What's the best way to do it? Should I put a timestamp to each entry I put in the remote and local server? If yes.. How does timestamp works in PHP(MySQL) and Android(SQLite)?

Thanks in advance! ;D

Was it helpful?

Solution

I'm assuming the data is read-only to the application and only changes on the server.

Here's how we do something similar:

The application passes up a "last_sync_date" to the server. If the last_sync_date is null, the server passes back all data.

The server always passes back a last_sync_date back to the application. The last_sync_date is in UTC server time. The application stores the last_sync_date.

Obviously, last_sync_date will be null the first time the app sends it, so the first time, it gets all data. From then on, it only gets new data.

Yes, a timestamp on each entry is used to determine which records are new/modified.

If need be, add a deleted column to each entry to "delete" them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top