How can I keep requesting a page every 5 seconds and not kill the battery?

不想你离开。 提交于 2019-12-06 03:57:19

I would consider using Android C2DM (from Android blog).

Basically, you register your users device with your server, and you can setup your server to push notifications to your users devices. You can then change the client to only make its requests when the server notifies that there is new data present.

This should work out well, as you will not need to make requests nearly as often. You will definitely save battery life this way.

Is there a reason why it needs to check every 5 seconds? You'd be better off having the server push a notification (via c2dm) to the device as to when an update is available. If you're continuously polling the server, you're going to drain the battery no matter how you implement it.

For chat-like functionality, the Smack (and Asmack variant) library is quite popular with Android developers. It provides a chat layer using XMPP.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!