简体   繁体   中英

How to synchronize and merge data between android device and google cloud datastore?

I am developing an app that uses an SyncAdapter on the android client to synchronized data with a Google Cloud Store ( GCS ) backend.

The adapter is working perfectly. Now my doubt is how to properly design the synchronization/merging algorithm taking into account the following issues:

  1. The data stored locally on the device can be modified since the last sync took place.
  2. The data stored on GCS could have changed since the last sync by another device.

I know how to read/write data from the GCS and manipulate it on the device, but not sure whether there is out-of-the-box functionality to perform this task of if I should implement my own from scratch.

Any example or hint would be really appreciated.

Simplest solution is to mark all changes (records?) with 'modified_date' and update records only with older modify date. If modify date is newer it means a collision/conflict (someone updated record before you were able to do that) - then, you can overwrite data or discard your changes.

I think the best way to do this is by following the example implemented in here: https://code.google.com/p/jumpnote/

The example is missing the GCS part, but all the merging logic is in there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM