Waking Up a Process with AlarmManager

To wake up a process with the AlarmManager, you have to set the alarm first. In the Task Reminder application, the best place to do that is right after you save your task in the saveState() method in the ReminderEditActivity. Before you add that code, however, you need to add four class files to your project in the src/ folder:

  • ReminderManager.java: This class is responsible for setting up reminders using the AlarmManager. The code for this class is shown in Listing 15-1 (see the next section in this chapter).
  • OnAlarmReceiver.java: This class is responsible for handling the broadcast when the alarm goes off. The code for this class is shown in Listing 15-2 (see the section “Creating the OnAlarmReceiver class,” later in this chapter). In addition to adding the code from that section, you also need to add the following line of code to the application element in your 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 is defined in the application element of the ApplicationManifest.xml file.

  • WakeReminderIntentService.java: This abstract class is responsible for acquiring and releasing the wake lock. The code for this class is shown in Listing 15-3 (see the section “Creating the WakeReminderIntentService class,” later in this chapter).
  • ReminderService.java: This class is an ...

Get Android™ Tablet Application Development For Dummies® 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.