I've an app that has multiple accounts and SyncAdapter. I wish to stop Syncing an account as soon as user chooses a different one. I'm doing:
ContentResolver.cancelSync(new Account(mAccount, ACCOUNT_TYPE), MyProvider.AUTHORITY);
ContentResolver.removePeriodicSync(new Account(mAccount, ACCOUNT_TYPE), MyProvider.AUTHORITY, new Bundle());
And it still syncs. How can I stop it from syncing?
ps i enabled Sync via setSyncAutomatically, requestSync initially.
the correct answer should be:
use cancelSync for cancelling a sync.
explanation according to this website:
We have the option to cancel a sync request, by calling cancelSync(). If the sync adapter is in “Pending” state, which means it hasn’t started yet, it’ll be canceled immediately and become “Idle”. If it’s already running, the onSyncCanceled() method on the sync adapter will be called. You can use it, for example, to set a “isSyncStopped” flag that the onPerformSync() will check regularly and respond to.
I figured it out.
we've to use:
int syncOnOff = 0;
ContentResolver.setIsSyncable(account, MyProvider.AUTHORITY, syncOnOff);
where syncOnOff is 0 for disable, > 0 for enable. |o| why not true false?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With