Search code examples
androidbroadcastreceiveralarmmanagerreboot

difference between boot receiver and broadcast receiver


I am using an alarm manager and I haven't been able to maintain the alarms when the system reboots so, I have read that I should use a boot receiver which extends broadcastReceiver but I want to know the exact difference between the receiver itself and the boot receiver.

The onReceive method of my broadcastReceiver actually takes me to a new activity using an intent should i use this code and paste it in the onReceive of the bootReceiver? or what exactly should I write in the bootReceiver?

I am very confused about this point because I have multiple alarms and I have given each one a unique requestCode.


Solution

  • There is no separate entity "Boot Receiver" in Android. Boot receiver is just broadcast receiver which responds to intent with action android.intent.action.BOOT_COMPLETED.

    I believe you will need to do couple of things:

    • Create a class which will inherit from BroadcastReceiver
    • Add it to Manifest and add info that it should handle android.intent.action.BOOT_COMPLETED
    • in onReceive code read all your alarms from persistent storage and set them again (so, they will be set again after each reboot).

    P.S. I recommend to read through: http://developer.android.com/reference/android/content/BroadcastReceiver.html