I am an iOS developer and recently started Android development. Currently I need the application to perform a repeating check regarding a remote resource (a JSON file) in the background, which I would like to:
- App finished launching
- Initiate scheduled repeating task in Application subclass
- Application will be noticed if there are any changes in the remote JSON file and handle it accordingly
After doing some research I found that there seems to have many ways to achieve this, while I can rule out some of them, I can't really tell the differences between the rest and which I should use.
I've found that to perform a scheduled repeating task, I can use the following classes:
ScheduledThreadPoolExecutor
IntentService
AlarmManager
Runnable
(withpostInBackgroundDelayed
/DelayedRunnable
, or maybeScheduledExecutorService
?)
And I've ruled out the use of:
ScheduledThreadPoolExecutor
, I've read that this is best used when multiple worker threads are needed, which in my case I only need oneAlarmManager
, this will be executed even when the app is not running, while I only need the task to be performed when the app is running
And for the rest, which are IntentService
and Runnable
, from my understanding so far:
IntentService
, needed to be started and stopped manually, tasks are invoked by sending an Intent to the service, and then the result is broadcastedRunnable
, like the block used in Objective-C, a specific segment of code to be executed at appropriate time
Other than these are there any other differences between them? Is my understanding correct? Are them both appropriate for my task? It it is the case, are there any considerations before choosing which one to use?
Thanks!