我已经在SDK中的SimpleSyncAdapter示例项目中实现了SyncAdapter,AccountManager和私有ContentProvider。
I have implemented a SyncAdapter, AccountManager and private ContentProvider along the lines of the SimpleSyncAdapter sample project in the SDK. It is all working well.
现在,当我从远程服务器下载了具有特定标志的新行时,我想向用户显示一条消息。当同步完成时,我需要来自SyncAdapter的回调,以便我可以执行查询并显示活动中的消息。我已经看到了一些关于StackOverflow讨论这个问题,但没有一个很好的答案。
Now I want to show a message to the user when new rows have been downloaded from the remote server that have a specific flag set. I need a callback from the SyncAdapter when a Sync has finished so I can do the query and display the message from an activity. I have seen a few questions on StackOverflow discussing this but none with a good answer.
如何从Android SyncAdapter监听进度?说SyncStatusObserver是无用的。用户mobibob建议使用ResultReceiver从同步线程回应UI。
How does one listen for progress from Android SyncAdapter? says that the SyncStatusObserver is useless. User mobibob suggests using a ResultReceiver to respond back to the UI from the sync thread.
如何知道同步何时完成?建议在SyncService中使用Intent。
How to know when sync is finished? suggests using an Intent in your SyncService.
如何向Android SyncManager发送同步完成信息?建议使用SyncResult。由maxpower47链接的示例代码使用SyncResult类报告异常,但不实际报告同步是否已成功完成。
How to signal sync-complete to the Android SyncManager? suggests using the SyncResult. The example code linked to by maxpower47 uses the SyncResult class to report exceptions but not to actually report if a sync was successfully completed.
我只是不知道是哪个是
推荐答案这是一个古老的问题,但是我没有看到任何解决方案。在过去的几天里做了一些研究,并没有很多的例子在syncAdapter处理网络请求和通知UI。
This is an old question but I did some research in the past days and there are not many exemples on syncAdapter handling network requests and notifying the UI.
首先你应该使用Loader with contentProvider使你的生活更轻松。你不需要注册内容解析器不再Loader为你做它。因此,这意味着您的UI会通知您进入内容提供商的任何内容。
First you should use Loaders with contentProvider to make your life easier. You don't need to register for content resolver anymore the Loader does it for you. So it means your UI gets notified for anything that goes into your content provider.
如果没有更改,该怎么办?一切都是最新的或您有网络错误。
What if nothing changed ? everything was up to date or you had a network error.
我喜欢最后一个更好的,因为它给你更多的粒度在syncAdapter发生的事件。
I like the last one better because it gives you more granularity on the events that happen in the syncAdapter.
更多推荐
Android SyncAdapter回调
发布评论