如何了解 Android 上的同步是自动启动还是手动启动?
我在我的应用程序中使用 SyncAdapter 。因此,同步可以是自动的(addPeriodicSync)或手动启动(requestSync)。
同步过程中如何知道它是如何启动的? 因为,如果它是手动启动的(从应用程序界面),我想显示 Toasts 等。
I use SyncAdapter
in my application. So, synchronization can be either automatic (addPeriodicSync) or started manually (requestSync).
How can I know in the process of synchronization how it was started?
Because, in case it is started manually (from app interface), I would like to show Toasts etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要通过 Toast 来通知您的用户,可能错误或异常除外。当同步进行时,用户已经在状态栏中看到圆形箭头“同步”图标。我的手机上有一些应用程序会在同步期间向我祝酒(每次),这非常烦人...特别因为当您的后台同步开始时,您的用户可能正在使用完全不同的应用程序,并且所有在突然的繁荣中,一些随机的 Toast 弹出,告诉他们同步正在进行中,他们认为它来自活动的应用程序,导致混乱。
如果您想向用户展示您的同步进度,请查看此 Google IO 2010 演示文稿:开发 Android REST
客户端应用程序 (pdf 和youtube)。它向您展示了如何将同步状态放入数据库的行中,并更新您的 UI。更好的模型,因为它为您提供了每行信息的粒度,并且仅在他们正确查看正在同步的数据时才显示。
Don't Toast to notify your user, except maybe for errors or exceptions. Users already see the circle-arrows "syncing" icon in the Status bar when it's in progress. I've had apps on my phone that Toast me during sync (every time) and it's annoying as hell... Especially because your users might be using a completely different app when your background sync starts and all of a sudden boom, some random Toast pops up telling them sync is in progress, and they think it comes from the active app, causing confusion.
If you want to show users your sync progress, look instead at this Google IO 2010 presentation: Developing Android REST
Client Applications (pdf and youtube). It shows you how to put sync state into rows in your database, and update your UI. Much better model, as it gives you per-row granularity for information and only shows up if they're looking right at the data being synced.
看起来使用额外功能是最好的方法。
Looks like usage of extras is the best approach.