1

First time I have tried to implement either of these and I am unsure which to use.

I want my application to create a time frame, e.g. 2/3/12 to 7/3/12. Multiple time frames such as this can be created. A different intervals (e.g. every 4 hours) I would like my application to preform some actions for each time frame. This needs to be done in the background.

I have first tried to implement this with a Service, but am having performing all the actions for each of the time frames concurrently. After reading the android blog "Multitasking the android way" I think that perhaps BroadcastReceivers are better.

Please advise

Shane
  • 2,315
  • 3
  • 21
  • 33

2 Answers2

2

Please see my answer about using the AlarmManager - Running task periodicaly(once a day/once a week)

If you are only running a process at a set time rather than constantly (e.g. monitoring audio levels) then you are going to ask a service to sit there 90% of the time and do nothing except waste battery power. The AlarmManager solves this problem as it notifies the broadcast receiver to execute at the given times.

Edit: Also bear in mind that after phone restart all alarms are removed so you will need to register a broadcast receiver to be notified of the device boot-up so you can re-register any Alarms that are needed.

Community
  • 1
  • 1
Graham Smith
  • 25,627
  • 10
  • 46
  • 69
  • Thank you. Did you get around to writing that tutorial? – Shane Mar 07 '12 at 18:21
  • Shane - good response and the answer is no as I am buried in work still however I may write one since you have asked. Saying that there is a good tutorial for here http://www.vogella.de/articles/AndroidServices/article.html – Graham Smith Mar 07 '12 at 18:23
2

You should probably be using the AlarmManager and a IntentService.

The AlarmManager will kick of your IntentService at specified intervals. You can kick off the IntentService for each set of actions.

rogermushroom
  • 5,486
  • 4
  • 42
  • 68