Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Android SyncAdapter sync

Tags:

android

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.

like image 486
Taranfx Avatar asked Apr 18 '11 16:04

Taranfx


2 Answers

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.

like image 192
android developer Avatar answered Oct 13 '22 10:10

android developer


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?

like image 20
Taranfx Avatar answered Oct 13 '22 11:10

Taranfx