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

Rebooting Devices

You probably forget things from time to time. It’s only human. The Android AlarmManager is no different. The AlarmManager doesn’t persist alarms; therefore, when the device reboots, you must set up the alarms again.

warning_bomb.eps If you don’t set up your alarms again, they simply don’t fire, because, to Android, they don’t exist.

Creating a boot receiver

The RECEIVE_BOOT_COMPLETED permission allows your application to receive a broadcast notification from Android when the device is done booting and is eligible to be interactive with the user. Because the Android system can broadcast a message when this event is complete, you need to add another BroadcastReceiver to your project. This BroadcastReceiver is responsible for handling the boot notification from Android. When the broadcast is received, the receiver needs to retrieve the tasks from the ReminderProvider and loop through each task and schedule an alarm for it, to ensure that your alarms don’t get lost in the reboot.

Add a new BroadcastReceiver to your application. For the Task Reminder application, the BroadcaseReceiver has the name OnBootReceiver. You also need to add the following lines of code to the application element in the AndroidManifest.xml file:

<receiver android:name=”.OnBootReceiver” android:exported=”false”>

<intent-filter>

<action android:name=”android.intent.action.BOOT_COMPLETED” />

</intent-filter> ...

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