Using Alarmmanager To Sync Data With A Server
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"