android - 停止 Android SyncAdapter 同步

标签 android

我有一个有多个帐户和 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/

相关文章:

android - 是否可以在 Android Google maps api v2 中显示/隐藏标记?

android - CollapsingToolbarLayout 仅在顶部展开

android - 如何使用 Facebook 好友制作 Android 多人游戏? (Google Play 游戏服务仅使用 G+)

android - 有没有办法在没有root设备的情况下将ffmpeg命令移植到Android?

java - Android WiFi Direct - 客户端/服务器 - ECONNREFUSED(连接被拒绝)更新

android - Gradle,定义一个属性集合

android - 替换 fragment 后,旧 fragment 的 View 仍保留在内容 View 中

android - 无法在运行 4.0.3 ICS 的 Android 设备上执行带有 map 的应用程序

java - 从geoserver获取 map 到argis sdk android

android - ACTION_VIDEO_CAPTURE 自动启动