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

Get Android Application Development For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.