The recommended pattern for Android's equivalent to cron jobs and Windows scheduled tasks is to use AlarmManager
. This works well when coupled with an IntentService
, as the service will do its work on a background thread and shut down when there is no more work to do.
There's one small problem: IntentService does nothing to keep the device awake. If the alarm was a WAKEUP variant, the phone will only stay awake on its own while the BroadcastReceiver handling the alarm is in its onReceive() method. Otherwise, the phone may fall back asleep.
WakefulIntentService
attempts to combat this by combining the ease of IntentService with a partial WakeLock.