Service, Handler, Timer, Runnable - Which To Use And How?
Solution 1:
Most things that need to perform a polling operation independent of any activities should use AlarmManager
for the scheduling, with your own IntentService
for the implementation of the actual polling logic. If you intend for the device to wake up out of sleep mode to do the work, you will need a _WAKEUP
alarm with the AlarmManager
and perhaps my WakefulIntentService
.
Solution 2:
Consider using the BuzzBox SDK: it perfectly fits your use case. There is also an RSS parser included in the library.
http://hub.buzzbox.com/android-sdk/
You can set up your Task to run every 15 minutes like this:
SchedulerManager.getInstance()
.saveTask(this, "*/15 8-19 * * 1,2,3,4,5", YourTask.class);
SchedulerManager.getInstance()
.restart(this, YourTask.class);
Notice the cron string: "*/15 8-19 * * 1,2,3,4,5" - your Task will run every 15 min, from 8am to 7pm, mon to fri.
The library takes care of the rest (rescheduling after reboot and after clock changes, error handling and retries...) and has some nice features: learn more: http://hub.buzzbox.com/android-sdk/scheduler
Post a Comment for "Service, Handler, Timer, Runnable - Which To Use And How?"