views:

41

answers:

1

Dear stackies,

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. :-s

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 credentials 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?

Thanks alot!

Best regards
S.

+1  A: 

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.

Juri
Juri, thanks, this will come in handy in future releases, I guess! At the moment that would reduce the range of customers to only those with Android 2.2 on their device. I'm not sure if I wanted that. But as I said: THANKS! :)
Sotapanna