This question was posed months ago, but I'd like to answer anyway...
onPerformSync()
is called when a new SyncThread is spun up to perform the sync operation. Each SyncAdapter spins up a SyncThread that is bound to the authority defined in sync-adapter.xml
, and multiple authorities cannot be defined in this xml file.
The AbstractThreadedSyncAdapter (the SyncAdapter super class) was simply not written to handle multiple authorities. It contains a final ISyncAdapterImpl
class that was implemented as a Singleton, so every time startSync()
is called, a sync will occur using the same authority.
Alternatively, were you initially trying to add @xml/syncadapter2
as additional meta-data within the SyncService? This is equivalent to registering multiple SyncAdapters to a single SyncService. It's technically doable (as you can define more than one meta-data tag within a service tag) however the OS itself is the culprit calling service.onBind(Intent intent)
on your service when it goes to run a synchronization, and you cannot easily control the intent it passes. If you could control it, you could put a key in the intent's bundle that would determine which of your registered syncAdapters to bind. And even that seems tough.
All that said, it would be less effort to implement different SyncAdapters for each authority (also with their own service), and abstract similar operations into a Utility class that get called in onPerformSync()
. This strategy is more maintainable in the long run anyway, because if one of the ContentProviders needed to be removed, it will be easier to remove its corresponding SyncAdapter and SyncService.