The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


AlarmManager and the Scheduled Service Pattern

Many applications have the need to get control every so often to do a bit of work. And, many times, those applications need to get control in the background, regardless of what the user may be doing (or not doing) at the time.

The solution, in some cases, is to use AlarmManager, which is roughly akin to cron on Linux and macOS and Scheduled Tasks in Windows. You teach AlarmManager when you want to get control back, and AlarmManager will give you control at that time.

Android 5.0 added a separate JobScheduler. Like AlarmManager, JobScheduler is designed for background work. JobScheduler is more sophisticated than is AlarmManager. For example, if you need an Internet connection to do your work, JobScheduler will only give you control if there is an Internet connection. If your app’s minSdkVersion is 21 or higher, you might consider using JobScheduler instead of AlarmManager. JobScheduler is covered in an upcoming chapter.

Prerequisites

This chapter requires you to have read the core chapters of the book, in particular the chapter on services.

Scenarios

The preview of this section was fed to a gremlin, after midnight.

Options

The preview of this section was lost in the sofa cushions.

A Simple Example

The preview of this section was eaten by a grue.

The Five set…() Varieties

The preview of this section is presently indisposed.

The Four Types of Alarms

The preview of this section did not survive Thanos's finger snap.

When to Schedule Alarms

The preview of this section was stepped on by Godzilla.

Archetype: Scheduled Service Polling

The preview of this section was whisked away by a shark-infested tornado.

Warning: Not All Android Devices Play Nice

The preview of this section did not survive Thanos's finger snap.

Debugging Alarms

The preview of this section took that left turn at Albuquerque.

Android 6.0 and the War on Background Processing

The preview of this section was lost due to a rupture in the space-time continuum.

Android 7.0 and OnAlarmListener

The preview of this section was abducted by space aliens.