Android – run your SyncAdapter immediately

25. 04. 2018

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!

10 Entrepreneurship Lessons Worth Thousands of Dollars

Instead of great success we have experienced great entrepreneurship lessons (for now). It also transformed me, a person who has …

Read article

Unique Czech words reflecting coronavirus now also with English explanations as Flashcard quiz in Vocabulary Miner

  Project Čestina 2.0 covering a variety of the modern Czech language with its slangs and new words has joined …

Read article

Performance of built-in higher-order functions Map, Filter, Reduce, and flatMap vs. for-in loop in Swift

  The most popular higher-order functions are map, filter, and reduce. We all use them since we think that syntax …

Read article

Contact