开发者

Confused about how to approach a registration and polling of messages with Android

What I need to do is auto-register device if not already done and then start polling messages with the credentials I received through this registration.

Now, after I read quite a bit about services, threads, asynctasks and the AlarmManager I'm totally confused about how to handle this.

So, there are my two main tasks. What would you recommend as a not-too-silly approach

  1. Registration I'm currently spawning a service from my UI thread if there are no credentials saved in the DB. Inside this service I start an asynctask that POSTs my request to the server and receives the credential开发者_高级运维s for the new device. stopSelf ends the service.

    Would you guys play it like that?

  2. Polling. I have not a single clue how I should do that. I'd like to poll messages quite often during the app is on top, lets say every minute. Otherwise, when the app is not running I thought about using the setInexactRepeating() method of the AlarmManager and poll lets say every 15 minutes.

Is there a better or a more gentle on resources way to do that?


I'm not sure, but this sounds like an application of the newly introduced C2D (Cloud 2 Device) API. You may want to check that out.

A sample implementation is the popular ChromeToPhone app.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜