Android Background Service and AlarmManager

Can someone give some briefing or perhaps more detailed information on the differences between the Android background service and the alarm manager?

How do they differ? And in what situation should I use each?

I am developing an application that needs to periodically download data from a web service. The application has several modules, and each module has a different time interval in order to download / synchronize data with the web service.

Let's say + Module A needs to be synchronized every 15 minutes + Module B needs to be synchronized every 1 hour + Module C needs to be synchronized every day + Module D needs to be synchronized weekly + Module E needs to be synchronized monthly

Which approach is better? And why?

Hello

+4
source share
2 answers

The alarm manager paints intentions. Your service may be broken and may be deleted if memory is not available. But if you are planning an alarm, you can call your specific service during an alarm. In your context, Alarm is a better option than starting a service.

Hope this helps you.

+6
source

With AlarmManager you can plan intentions. Your service or BroadcastReceiver can listen to these planned intentions and complete tasks at a given time. You can not only use AlarmManager to implement program logic.

You can use AlarmManager to send an Intent every 15 minutes with an action for A, every hour for B, etc. Either your modules are implemented as independent services, or you decide what to do.

Remember also that long operations should not be performed in BroadcastReceiver.

0
source

All Articles