I am working on an Alarm Clock project and i want to edit my already set Alarm.
when I edit alarm then alarm time is updated but values that I send by using putExtra()
are not changing. I am using PendingIntent.FLAG_ONE_SHOT
flag.
But when I set flag PendingIntent.FLAG_UPDATE_CURRENT
all putExtra()
values are also change but now problem is that, when i click on stop button and finish()
the current activity it calls again.
means when I go to finish the activity it calls again on button click while I am finishing current activity. please help me. Thanks in advance.
My prefered way to update a PendingIntent in AlarmManager is to Cancel it and re-set it
do not forget to cancel :
1) AlarmManager.cancel(pendingIntent)
with a pendingIntent that match your pending intent (same class , same action ... but do not care about extra see IntentFilter)
2) pendingIntent.cancel();
3) pendingIntent = new PendingIntent()
... and do other settings
4) AlarmManager.set(...
to provide new PendingIntent
Each alarm has its unique identifier, if you want to update an alarm, you can create a new one with the same UNIQUE_ID.
PendingIntent pi = PendingIntent.getBroadcast(this, PENDING_INTENT_ID, intent, 0);
Check this answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With