I want to make a service which fire alarm manager in every 1 min interval..But my Alarm run once(first time only). I follow Lalit Answer
private class Rec
I know this question already has an answer, but for others who have had the same issue but need to use AlarmManager
. The reason why it only runs once is because the new PendingIntent
you create does not get recreated, but rather is reusing the one before it. So in other words, the reason why your alarm only ran once was because it kept reusing it. Using the flags to refresh the intent extras if there are any should be doing the trick, but that also does not work.
A trick to use to make sure it does not reuse the PendingIntent
and ultimately the Intent
you provide is to use setAction()
and give it some unique "Action". I did it like this:
intent.setAction("com.yourname."+System.currentTimeMillis());
As you see this makes sure its unique. Though, the above accepted answer it the best approach, if someone does not want that, they need to understand why and how to remedy that issue. Hope it helps anyone else.