0

On Android device, when you go to Settings > Accounts > your Google account > and check Sync Calendar, what exactly gets executed?

I suppose there must be something like a built in sync adapter which connects to the Google Calendar server, gets the necessary changes and updates local Calendar Provider tables. Is there any way to use this functionality rather than implement my own calendar sync adapter (which does not look like a trivial task at all) to keep Calendar Provider tables synced?

If it is not possible, is there any sample of onPerformSync() calendar-specific implementation?

To be clear: I know how to write, configure and use a service, sync adapter, content observer, ContentResolver.requestSync() etc. What is still unclear to me is how to implement specific onPerformSync()to sync Google Calendar and whether I really have to write my own implementation for it.

Zmiter
  • 298
  • 4
  • 15

1 Answers1

0

The sync adapter component does not automatically do data transfer. Instead, it encapsulates your data transfer code, so that the sync adapter framework can run the data transfer in the background, without involvement from your app. When the framework is ready to sync your application's data, it invokes your implementation of the method onPerformSync().

The following snippet shows the overall structure of onPerformSync():

/*
* Specify the code you want to run in the sync adapter. The entire
* sync adapter runs in a background thread, so you don't have to set
* up your own background processing.
*/
@Override
public void onPerformSync(
Account account,
Bundle extras,
String authority,
ContentProviderClient provider,
SyncResult syncResult) {
/*
* Put the data transfer code here.
*/
...
}
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
  • I know what sync adapter does. The question is how to **implement** onPerformSync() for specific Google Calendar synchronization. And another one: Android **knows** how to sync when you click Settings > ... > Sync Calendar; why can't I use this functionality as a default Sync Adapter in my app? – Zmiter Apr 13 '16 at 10:33