我有一个有多个帐户和 SyncAdapter 的应用程序。我希望在用户选择不同帐户后立即停止同步帐户。我在做:
ContentResolver.cancelSync(new Account(mAccount, ACCOUNT_TYPE), MyProvider.AUTHORITY);
ContentResolver.removePeriodicSync(new Account(mAccount, ACCOUNT_TYPE), MyProvider.AUTHORITY, new Bundle());
它仍然同步。我怎样才能阻止它同步?
ps 我通过 setSyncAutomatically 启用了同步,最初是 requestSync。
最佳答案
正确答案应该是:
使用cancelSync用于取消同步。
解释根据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.
关于android - 停止 Android SyncAdapter 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5705886/