Android update pending alert

I am working on the Alarm Clock project and I want to edit an already installed Alarm. when I edit the alarm, the alarm time is updated, but the values ​​I send with putExtra() do not change. I use the flag PendingIntent.FLAG_ONE_SHOT .

But when I set the PendingIntent.FLAG_UPDATE_CURRENT flag, all putExtra() values ​​also change, but now the problem is that when I click the stop button and finish() , the current operation calls again.

means that when I go to finish the operation that he calls again, press the button while I finish the current activity. please, help. Thanks in advance.

+6
android android-alarms
source share
2 answers

My preferred way to update the PendingIntent in AlarmManager is to cancel it and reinstall
don't forget to cancel:

1) AlarmManager.cancel(pendingIntent) with a pending action that matches your pending intent (same class, same action ... but don't care about extra see IntentFilter )
2) pendingIntent.cancel();
3) pendingIntent = new PendingIntent() ... and make other settings
4) AlarmManager.set(... to provide a new PendingIntent

+6
source share

Each alarm has its own unique identifier. If you want to update the alarm, you can create a new one with the same UNIQUE_ID.

 PendingIntent pi = PendingIntent.getBroadcast(this, PENDING_INTENT_ID, intent, 0); 

Mark this answer

0
source share

All Articles