Skip to content Skip to sidebar Skip to footer

Using Alarmmanager To Sync Data With A Server

First of all, I apologize for my English. I need to sent data to a server and query for data in that server from time to time, maybe from week to week. So I'm going to use the Ala

Solution 1:

You can, most certainly, register two separate Intents, with the AlarmManager. Just be sure to use different ids in your call to PendingIntent.getService... (and, btw, I suggest that you not use 0 as an id. 0s are just to easy to come by, in Java). Use the ACTION, or a parameter in the Extras, to distinguish between them.

There is no reason to use a BroadcastReceiver: you can fire the intent at the Service directly. If you are concerned about security, don't export the Service. A PendingIntent is fired from within your application, so there is no need to make the Service externally visible.

Finally, although you are right about the overhead for a SyncAdapter, it really is a great way to do exactly what you are trying to do. There is a good description of how to write one in EnterpriseAndroid (I am one of the authors). Once you get through the boiler-plate, it is actually almost elegant.

There is an example of a minimal SyncAdapter here.

Post a Comment for "Using Alarmmanager To Sync Data With A Server"