How to signal sync-complete to the Android SyncManager?

女生的网名这么多〃 提交于 2019-12-07 04:15:24

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5785482/how-to-signal-sync-complete-to-the-android-syncmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!