Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updating alarm from pending intent in android

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.

like image 392
Sunit Kumar Gupta Avatar asked Dec 27 '10 12:12

Sunit Kumar Gupta


2 Answers

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

like image 77
Emmanuel Devaux Avatar answered Sep 24 '22 17:09

Emmanuel Devaux


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

like image 40
Nissar Avatar answered Sep 20 '22 17:09

Nissar