O'Reilly logo

Asynchronous Android by Steve Liles

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling alarms

Now that we know how to schedule alarms, let's take a look at what we can schedule with them.

Essentially, we can schedule anything that can be started with a PendingIntent, which means we can use alarms to start Activities, Services, and BroadcastReceivers. To specify the target of our alarm, we need to use the static factory methods of PendingIntent:

PendingIntent.getActivities(…)
PendingIntent.getActivity(…)
PendingIntent.getService(…)
PendingIntent.getBroadcast(…)

In the following sections, we'll see how each type of PendingIntent can be used with AlarmManager.

Handling alarms with Activities

Starting an Activity from an alarm is as simple as registering the alarm with a PendingIntent created by invoking the static getActivity

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required