31.10.2011

Last Updated on

Android has great support for server <-> client synchronization. There is lot of thinks to implement and the documentation is not fully complete, but it worth.

When you want to know more about SyncAdapters, ContentResolvers, ContentProviders and AccountAuthenticators you should read Sample SyncAdapter example on Google’s Android developer site.

Force sync

Now what to do, when your synchronization is ready to use and you want to allow user to fire “sync now” action? It’s just a few lines of code:

Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_FORCE, true);
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(null, MyContentProvider.getAuthority(), bundle);

Just call the above code and your Android device will we synchronized immediately, even if background data are disabled (thanks to “SYNC_EXTRAS_MANUAL”)!

Enjoy syncing!

Vladislav Skoumal
SKOUMAL CEO