0

I have been trying to implement SyncAdapter to sync data between client(android device) and server using sqlite.The same data will be shared between different devices.

On Update: As soon as a particular record is updated on one client device it will be pushed to the server. At that moment the updated record should also be synced from the server to other connected devices.

Now, when we send sync request from other connected devices, what is the best way to know which record get updated on the server?

salih kallai
  • 879
  • 2
  • 13
  • 34
ThunderDragon
  • 613
  • 3
  • 13
  • 31

1 Answers1

2

Here is what I would do to achieve this:

  • First, consider using timestamps. Here is how that could work;
  • In your database table (remotely), have a column updated_at which as soon as you sync your fresh data up, you should set a new timestamp for it.
  • In your android code, you can simply store lastSyncTime in your preferences then compare with what you get from your server column.

You can easily pull the value from an endpoint /last_sync/ to see if the sync_time has changed.

By comparing the two timestamps, you can then decide as to whether you want to sync down new data or keep the old until the new ones are synced.

I hope this helps. Good luck!

Eenvincible
  • 5,641
  • 2
  • 27
  • 46
  • Thank you for quick reply. But if there are thousands of record in the table(remote server) we have to compare the timestamp thousand times. This comparison will increase as the number of record increases in the server. Is there any better way to do this? – ThunderDragon Aug 18 '15 at 13:08
  • If you run a sql statement/query with something like "where updated_at > lastSync, that should do it. – Eenvincible Aug 18 '15 at 13:23