SyncAdapter何时在android上运行同步?
假设我的应用程序实现了 SyncAdapter 功能并且没有定义定期同步。在这种情况下什么时候会发生同步?我可能想到的第一个场景是本地 ContentProvided/数据库内容更改。 服务器变更有什么影响? SyncAdapter 如何知道这一点?
Let's say, my application implements SyncAdapter functionality and doesn't define periodic syncs. When synchronization will happen in such scenario? First scenario I may think about is local ContentProvided/database content change.
What is about server changes? How SyncAdapter will know about that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有定期同步设置,则当您的代码使用您的帐户和权限显式调用
ContentResolver.requestSync(Account account, Stringauthority, Bundle extras)
时,就会发生同步。另外,如果您的ContentProvider插入或更新或删除函数调用
ContentResolver.notifyChange(Uri uri, ContentObserverobserver, booleansyncToNetwork)
,如果boolsyncToNetwork为true(默认),它也会触发同步。这里引入了短暂的延迟,以确保一批数据库更改仅导致一次同步,而不是每次更改一次。请注意,您的代码应该调用notifyChange
,因为这是 Android 在 UI 反映的内容发生更改后通知您的 UI 进行更新的方式。如果服务器数据库发生更改,您的应用程序将不会知道,因为同步没有发生。两个选项:
If you have no periodic sync setup, Sync will happen if your code explicitly calls
ContentResolver.requestSync(Account account, String authority, Bundle extras)
with your account and authority.Also, if your ContentProvider insert or update or delete functions call
ContentResolver.notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork)
, if the bool syncToNetwork is true (the default), it will also trigger a sync. There's a short delay induced here, to ensure that a batch of database changes only causes one sync, not one per change. Note that your code should be callingnotifyChange
because it's how Android signals your UI to update after Content that the UI is reflecting had been changed.If the server database changes, your app won't know, because sync isn't happening. Two options: