O'Reilly logo

Android™ Tablet Application Development For Dummies® by Donn Felker

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

I admit, after a long day and a good night's rest, I forget things from time to time. I'm only human, right? I usually have to be reminded of certain things when I wake up; that's just the way it is. The Android AlarmManager is no different. The AlarmManager does not persist alarms; therefore, when the device reboots, you must set up the alarms all over again. Although it's not a huge pain in the butt, it's something worth knowing.

image If you do not set up your alarms again, they simply will not fire, because to Android they do not exist.

Creating a boot receiver

In the last chapter, you set up the RECEIVE_BOOT_COMPLETED permission. This 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 connect to SQLite through the RemindersDbAdapter, loop through each task, and schedule an alarm for it. This procedure ensures that your alarms don't get lost in the reboot.

Add a new BroadcastReceiver to your application. For the Task Reminder application, I'm giving it a name of OnBootReceiver ...

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