updating alarm from pending intent in android
Asked Answered
V

2

7

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.

Vengeance answered 27/12, 2010 at 12:53 Comment(0)
L
7

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

Literatim answered 19/8, 2011 at 18:11 Comment(2)
In case of calendar events setting alarm, If we use a local variable and not static, we can assign various time for various events. But it seems that you have shown static pendingIntent exampleCalcaneus
Is REALLY this is the only way to update the alarm? WORKED FOR ME.Yapon
U
2

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

Unstep answered 26/2, 2014 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.