Best Way to Frequently Poll a Server from an Android App

I have an Android app which needs to poll a web server at 2 second intervals.

So I would like to know what the best way to do this would be. My first thought was to use an AlarmManager but I believe this is no good for anything more frequent than about 5 minute intervals. I have also considered using a service but I am concerned this will drain the battery. Are there any options I haven't considered? What is the best way to poll a server very frequently without killing the battery?

I also know that GCM is the ideal way to sync with a server but unfortunately it is not an option at this time.

Edit: ok, it seems from your comments that it is as I feared and there's no good solution for this. I will probably implement it in a service and press for a push mechanism instead. Thanks for your help.


The solution I have come to is gaining agreement to redesign so that the server pushes to the app only when the data has changed (it won't change that often, realistically).

In the meantime I have made some small changes to the service so that it cancels all requests when the app isn't in the foreground and reduced the poll time to 5 seconds (better than nothing, right).

链接地址: http://www.djcxy.com/p/74516.html

上一篇: android将数据发送到.net web服务

下一篇: 从Android应用程序频繁轮询服务器的最佳方式