In my app I want to run some code every day at a specific time using an AlarmManager
. In the android documentation I found this:
Registered alarms are retained while the device is asleep [...] but will be cleared if it is turned off and rebooted.
And that is the problem. I want to run the code even if the user reboots the phone. If the user reboots the phone he currently has to relaunch my app to start alarms again. How can I prevent this? Is there a better mechanism I should use instead?
Create Boot Receiver using following code :
In your Manifest, register this Broadcast receiver :
And don't forget to add permission in AndroidManifest.xml :
Use can u create service using broadcast reciever on device boot up
Permission:
You will need to add a boot receiver in your manifest like this
And then create the boot receiver class like this...
My alarm helper class is a simple start of day alarm like this...