O'Reilly logo

Android Application Development For Dummies, 2nd Edition by Donn Felker, Michael Burton

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

Waking Up a Process with AlarmManager

To wake up a process with AlarmManager, you have to set the alarm first. In the Task Reminder application, the best place to do it is right after you save a task in the save button’s onClickListener(). Before you add that code, however, you need to add four class files to your project:

check.png ReminderManager.java: This class is responsible for setting up reminders using AlarmManager. The code for this class is shown in Listing 13-1.

check.png OnAlarmReceiver.java: This class is responsible for handling the broadcast when the alarm goes off. The code for this class is shown in Listing 13-2. (See the section “Creating the OnAlarmReceiver class,” later in this chapter.) You need to add the following line of code to the application element in the AndroidManifest.xml file for your application to recognize this receiver:

<receiver android:name=”.OnAlarmReceiver” />

remember.eps The leading-period syntax informs Android that the receiver is in the current package — the one that’s defined in the application element of the AndroidManifest.xml file.

check.png WakeReminderIntentService.java

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