How to signal sync-complete to the Android SyncMan

2019-05-02 11:59发布

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?

2条回答
我命由我不由天
2楼-- · 2019-05-02 12:20

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

查看更多
成全新的幸福
3楼-- · 2019-05-02 12:28

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.

查看更多
登录 后发表回答