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:
ReminderManager.java: This class is responsible for setting up reminders using AlarmManager. The code for this class is shown in Listing 13-1.
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” />
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.
WakeReminderIntentService.java
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access