Can somebody explain the common way to handle C2DM intents work?
I have an app that does intelligent polling - it's essentially a messaging application - so it polls the server to check your inbox for new messages. There is an activity UI, and a background Service that polls conservatively.
Now to supplement the polling I have included C2DM - presumably to push inbox content that sits unread for 30 minutes.
So when I receive a C2DM RECEIVE intent, I am telling my background service to go poll.
How will this work?
I assume C2DM's main use case is an "idle" phone (i.e. in your pocket, screen off). So you get a RECEIVE intent, grab a wake lock, and fire off the background service to go poll; returning wake lock once you send an intent to the background service.
How long will the background service stay alive?
Won't android just kill it off right away?
Should I just try to do 1 server ping and then die?
I'm just confused about how much processing I can do after getting a C2DM intent.
The approach you're suggesting sounds solid. To use C2DM as a way to supplement polling is a good appraochapproach. C2DM on its own is not 100% reliable (it never will be) and your design protects against that.
The service will run until it finishes its work. I expect it would show a notification to the user, or update a message list.
I'd set the service up to do an exponential-back-off retry, and have it try X times before failing. If it fails, then the next time a poll occurs it'll be brought up to date. I wouldn't want the background service to try for too long, as that's what the polling code is there to do.
Your service will keep going unless the OS needs memory badly. You could force the service to be a foreground service (with notification icon) but I don't expect that's necessary.
I'm assuming your service is polling the service regularly, so it will make up for any failure in the C2DM message to make a server request.