My question is rather simple but might come with a complex answer.
I'm making an App that checks on an online mysql db (via a php script on the website) for new updates. Sometimes this updates will tell the App it has to download form a FTP server.
The App should start on boot and check for updates every 15 minutes.
I've read in the web I should either use a service or a AlarmManager but I don't know which one is better.
Also, I've read a lot of pages that say that AlarmManager will "Wake Up" the device but I've failed to understand what this really means and why it's different in a service. Does this means that if the Phone is turned off it will turn it on or that it will turn on the screen?
I only need the phone to do the task in the background when it's on, I don't need it to turn the screen on or power up the device.
I've read in the web I should either use a service or a AlarmManager but I don't know which one is better.
It's not an "or". It's an "and". You will need to use AlarmManager
to trigger the work to be done by a Service
.
I've read a lot of pages that say that AlarmManager will "Wake Up" the device but I've failed to understand what this really means
An AlarmManager
_WAKEUP
event type (e.g., ELAPSED_REALTIME_WAKEUP
) will wake up the device out of sleep mode. That, in conjunction with something like WakefulBroadcastReceiver
and an IntentService
, can arrange for you to do your work periodically even though the device would ordinarily be asleep (screen and CPU in a sleep state).
I only need the phone to do the task in the background when it's on, I don't need it to turn the screen on or power up the device.
Then you can use AlarmManager
with a non-_WAKEUP
alarm type (e.g., ELAPSED_REALTIME
). I would still recommend using WakefulBroadcastReceiver
and an IntentService
, to make sure that the device does not fall asleep in the middle of what you are doing, as that may cause problems for your work.