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 noti开发者_如何学Pythonfication 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?
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.
精彩评论