如何向 Android SyncManager 发出同步完成信号?
我在我的 SyncAdapter 中使用 cancelRequest() ,就在它退出线程之前,但我随后决定它仅供另一个想要取消正在进行的同步的实体 (UI) 使用(花费太长时间,哎呀,等)
现在我的同步认为总是有一个待处理的请求 - 我用它来忽略新请求。
我要做的另一件事是服务中的一个侦听器线程,它正在侦听 ContactsContract.AUTHORITY 的更改,以便它可以启动我的聚合同步。
更新:此侦听器线程正在泄漏。当我完成后,我会发出 .stop() ,但是,有一个处理程序我认为它保持活动状态并防止服务停止。
我想将 SyncResults 发送到某个实体(即 SyncManager),该实体跟踪此类事物的待处理、回收等。
我缺少什么?
I was using cancelRequest() from within my SyncAdapter, just before it exits its thread, but I then decided that was only intended to be used by another entity (UI) that wants to cancel a sync in progress (taking too long, oops, etc.)
Now my sync thinks there is always a pending request - which I use to ignore new requests.
The other thing that I have going is a listener thread in a Service that is listening for changes to the ContactsContract.AUTHORITY so it can kick off a sync of my aggregation.
UPDATE: This listener thread is leaking. I am issuing a .stop() when I am done with it, however, there is a handler that I think is staying alive and keeping the service from stopping.
I would like to send SyncResults to some entity (i.e., the SyncManager) that tracks such things for pending, recycle, etc.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用一个例子来详细说明 shunty 的答案:
这是一个 设置SyncResult的示例。我只是用它来设置统计字段中的异常数量。然后我看到的结果是“帐户和帐户”中的该同步项目显示一个错误图标。同步屏幕。
To elaborate on shunty's answer with an example:
Here is an example of setting the SyncResult. I just use it to set the number of exceptions in the stats field. The result I see then is that an error icon is displayed for that sync item in the Accounts & sync screen.
您可以使用 SyncResult 此类用于传达同步操作到SyncManager。根据此处的值,SyncManager 将确定同步的处置以及将来是否需要安排新的同步操作
You can use the SyncResult This class is used to communicate the results of a sync operation to the SyncManager. Based on the values here the SyncManager will determine the disposition of the sync and whether or not a new sync operation needs to be scheduled in the future