The point behind using
AlarmManager is so that your service only needs to be in memory when it is doing actual work, and can go away in between
AlarmManager events. You have managed to not do that, and therefore your code will not work reliably.
If you want to "send email every 9 mins", you should:
View original answer
BroadcastReceiver to be a public Java class, registered in the manifest via a
<receiver> element, and remove the
Switch your service to be an
IntentService, so you get a background thread (which you need for your work, but your current code lacks) and so the service can automatically shut down when there is no more work to be done.
Add in the logic for the
WakeLock that you will need since you are using a
_WAKEUP-style alarm. You could combine this and the previous steps by switching to my
WakefulIntentService, if you wish.
Deal with the case where the user reboots the device, if you want your alarms to continue after the reboot, such as by scheduling them again via an