开发者

Long-polling solution in android native app?

i need to build a app to do live reporting, can you suggest a solution that enables real-tim开发者_Python百科e communication? I'd like to go with long-polling this approach.

It will be an Android native app, not a web app.

Is there something already written so I do not need to implement it from very beginning.?

I'm a django, python developer.


This is not a polling solution but when I needed something like this I created a foreground service that creates a persistent socket connection to my server. I then registered with some broadcast receivers to maintain my service, on BOOT_COMPLETED and CONNECTIVITY_CHANGE. This worked better for me then C2DM because I had more control of the system and was virtually real time. C2DM is a fire and forget system and is not guaranteed to be reliable. You will have to manage the socket between changes in connections, and maybe hold some kind of wakelock.

For a polling solution, you could also build a web server and poll with http requests. This will avoid the need to manage the socket between connection changes but is not a real time solution.


On the receiving end, there is the Android Cloud to Device Messaging Framework (Google's implementation of push notifications): http://code.google.com/android/c2dm/

Note: this requires Android 2.2 and up (~84% of users as of today)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜