Android synching data between users Android synching data between users android android

Android synching data between users


You should definitely use ContentProvider and SyncAdapters. You should:

  • Wrap your database functionality with the ContentProvider interface
  • Setup a SyncService matching the authority of the ContentProvider
  • In your SyncAdapter specialization, you will override onPerformSync()
  • Use SharedPreferences storage to keep track of your sync parameters e.g. lastSync time, etc.

    final SharedPreferences syncMeta =                    mContext.getSharedPreferences("sync:" + account.name, 0);long lastSyncTime = syncMeta.getLong(LAST_SYNC, 0);long lastServerSyncTime = syncMeta.getLong(SERVER_LAST_SYNC, 0);
  • This can easily tell you if its the first sync and you can do the initial handling here

  • You will write your algorithm here for sync i.e one way/two way.
  • I find it useful to record timestamps and server database ID in your Android records to help with sync. This can help you with your merge strategy.
  • Use the ContentProvider here for DB operations. ContentProviders provide a uniform way of accessing your data from your app as well as sync adapters. They will notify the system of updates so that the framework and schedule sync. They can also be helpful as public interfaces of your data to other apps should you choose to do so.

  • Also, by using SyncService you are saving battery. The system will use network tickles to kick of sync operations and its best if they are batched together for all apps instead of each app waking up the system

Finally,

There are two samples you should look at. They pretty much cover everything I explained

  1. JumpNote - http://code.google.com/p/jumpnote/source/browse/
  2. SampleSyncAdapter - http://developer.android.com/resources/samples/SampleSyncAdapter/index.html

Both these apps use Google App Engine for the cloud component. Its easy to get started with, so definitely explore that options.


First create a local DB in android. and ur saving Location details details. after saving it send to cloud/server DB.

Next occasionally U need to sync which cloud/server DB. so write a Service in android like take a specific interval and sync with clound/server DB.

merging so take a time stamp in a table. and check that time stamp and update accordingly.