Running An Android Service After Every 20 Sec Using Alarmmanager Doesn't Restart On Killing The App From The App List
Solution 1:
Here's a few things:
Please remove the "alarmRunning" code where you set the alarms. Just do it all the time. If the alarm is already set, setting it again will just cancel the old one and set a new one. This isn't a problem.
You cannot rely on the existence of a PendingIntent
to determine whether or not an alarm is set in the alarm manager. This is most likely the reason why you get no alarms after killing and restarting your app.
Also, you cannot reliably schedule an alarm every 20 seconds using setRepeating()
. Android has strict power management rules and will not reliably trigger a repeating alarm that is less than 2 minutes on most devices. You might see this alarm going off after 2 or 3 or 5 minutes instead of 20 seconds, depending on the power management settings, battery level, busyness of the device, whether it is sleeping, etc.
If you really want something running every 20 seconds then you should set a single alarm and when that alarm goes off, process it and set the next alarm for 20 seconds from now.
Post a Comment for "Running An Android Service After Every 20 Sec Using Alarmmanager Doesn't Restart On Killing The App From The App List"