I’m developing an app that periodically fetches data from server. Now I’m using a ScheduledThreadPoolExector, but I think is not clean enough, so I decided to use AlarmManager to create periodic tasks.
Which is better for this tasks: BroadcastReceiver or Service? I’ve read that one of these have the 10 sec limitations, or do both have this limitation?
Indeed a BroadcastReceiver can only live for 10seconds. A service can live longer (depending if Android OS needs resources, it can kill your app).
Your Service can be a ‘normal’ service or an IntentService (which gets killed automatically after no more Intents are available to process).
I would recommend a IntentService.
You can create an Intent which will be received by the IntentService, and add this Intent to the AlarmManager.