Android的 - 如何得到通知时同步完成后,请求与ContentResolver.requestSync同步(时) [英] Android - how to get notified when sync finishes, when requesting a sync with ContentResolver.requestSync()
问题描述
我有自己的的ContentProvider
和 SyncAdapter
这两个做工精细。
I have my own ContentProvider
and SyncAdapter
which both work fine.
我将它们设置为与 ContentResolver.setSyncAutomatically()
的这项工作被自动同步。我还可以开发工具测试同步 - >同步测试仪
I set them to be automatically synced with ContentResolver.setSyncAutomatically()
an this work. I can also test the sync with Dev Tools -> Sync Tester.
现在我想从我的应用程序请求同步(如果我们没有数据还),当它完成通知,这样我就可以更新了界面(我展示一个进度条带标志,而它的同步)。我与 ContentResolver.requestSync()
这样做,但我还没有找到一种方式来获得通知时同步完成。
Now I would like to request a sync from my app (if we have no data yet) and be notified when it finishes, so I can updated the interface (I'm showing a progress bar with logo while it's syncing). I'm doing this with ContentResolver.requestSync()
, but I have not found a way to get notified when the sync finishes.
有谁知道如何做到这一点?谢谢你。
Does anyone know how to do this? Thanks.
推荐答案
使用<一个href=\"http://developer.android.com/reference/android/content/ContentResolver.html#addStatusChangeListener%28int,%20android.content.SyncStatusObserver%29\"相对=nofollow> addStatusChangeListener()
会给你回调时,同步是 SYNC_OBSERVER_TYPE_ACTIVE
或 SYNC_OBSERVER_TYPE_PENDING
。这是非常奇怪的是没有完成的事件。
Using addStatusChangeListener()
will give you callbacks when the sync is SYNC_OBSERVER_TYPE_ACTIVE
or SYNC_OBSERVER_TYPE_PENDING
. It is well weird that there is no finished event.
下面是一个解决方法通过菲利克斯建议。他建议,你应该沟 ContentResolver的
赞成广播。
Here is a workaround suggested by Felix. He suggests that you should ditch the ContentResolver
in favour of Broadcasts.
这篇关于Android的 - 如何得到通知时同步完成后,请求与ContentResolver.requestSync同步(时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!