Search code examples
androidbroadcastreceiveralarmmanager

BroadcastReceiver and AlarmManager at Device Boot


i've got a Activity in which an alarm is started at a time which can be choosen by the user; the time is stored in a database. Than a BroadcastReceiver is called which fires a notification at the specific time. So everything is working, but now i want to start the alarms also when the device is rebooted and i don't know how exactly i can do this. According to this site Alarm Notification i should implement an other BroadcastReceiver which starts when the device is booted and fires the alarms like i do in my other BroadCastReceiver. But on all other sites, they advice to implement a BroadcastReceiver which starts an extra service and than fires the alarms. Also i wonder if it's possible that the BroadcastReceiver which could be started when the device is booted does have access to my database in which the date and time of the alarms to be fired are stored. Thanks everybody


Solution

  • Yes, as it's part of the same application it has access to the database. So you could receive notification of device boot then set your alarms up using the time in the database, or fire the alarms. Or both.

    Hope this helps.