I have dozen accounts in AccountManager and when add new account Android start synch开发者_Go百科ornizing all accounts. Since there are a lot of them, takes at least 15 seconds to start my synchronization.
Is there any way to stop/cancel synchornization of all accounts when I add new one, so I can call ContentResolver.requestSync
and start synchornizing only my account at that moment?
Thanks,
Aleksandar Ilić.
Sync is intended as a background service. 15 seconds seems like a totally reasonable delay before the start of a sync, especially when adding a new account (should?) be a very infrequent event. Another thought is that if you have a dozen accounts active, you might try to think of how to reduce that count -- What do you have so many after all? Multiple accounts at once site?
Are you worried about first-time setup responsiveness, or do you have some use case that requires you to actually add and remove accounts frequently?
If the latter, look at just turning ContentResolver.setIsSyncable()
on and off for the given content/account pair. When false, the checkbox on the accounts page is greyed out and no sync will occur. That might meet your needs better than creating and destroying the account.
That said, you can try speeding it up.
manually call
ContentResolver.requestSync (Account account, String authority, Bundle extras)
and look at the extras values defined in ContentResolver. You might trySYNC_EXTRAS_MANUAL
andSYNC_EXTRAS_EXPEDITED
.A more extreme case (which might really piss off your users if you screw it up...) would be to save the current state of master sync, and then explicitly disable master sync (ContentResolver.setMasterSyncAutomatically(boolean sync)) and push a synch with
SYNC_EXTRAS_MANUAL
to override and then restore master sync to its initial state once your sync is finished.
The question is how to do that... You'd need to kick that off from the account creation code in your app, I would think.
精彩评论