Sencha touch 中的后台服务
我正在使用 Sencha touch 和 PhoneGap 构建 Android 移动应用程序(RSS 阅读器)。我创建了某种后台服务,每 12 小时检查一次新帖子并更新应用程序。当有新帖子时,会显示通知( http://developer .android.com/guide/topics/ui/notifiers/notifications.html )
我为此使用 window.setInterval() 。这看起来是一种肮脏的方法,但它确实有效。
您对此有何看法?是否有更好的方法来完成工作?
I am building an mobile app ( RSS reader ) for Android with Sencha touch and PhoneGap. I have created some sort of background service that checks every 12 hours for new posts and update the app. When there is a new post a notification is shown up ( http://developer.android.com/guide/topics/ui/notifiers/notifications.html )
I am using window.setInterval() for this. This seems like a dirty way to do it, but it works.
Whats your opinion about this and is there a better way to get the job done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 JS 中,唯一的其他方法是 长轮询 带有 XHR 请求。然后,可以在通知出现时推送通知,而不是每 12 小时推送一次。然而,这可能不是一个很好的解决方案,因为它会占用服务器资源并需要持续的连接。
因为您也在使用 PhoneGap,所以您可以编写 Android 插件将实现一个 JS 对象,能够注册回调并在特定时间调用它们。或者实现 @ballmw 建议的 API。
最后,setTimeout/setInterval 如果工作正常的话可能没问题。
The only other way, in JS, to do it would be a long poll with an XHR request. The notifications can then be pushed when they show up instead of every 12 hrs. However this probably isn't a great solution as it will tie up server resources and require a constant connection.
Because you are also using PhoneGap, you could write a plugin for Android that will implement a JS object with the ability to register callbacks for and call them at a particular time. Or implement the API that @ballmw suggested.
In the end, setTimeout/setInterval is probably fine if it works properly.