I am trying to make some alarms after the user selects something with a time from a list and create a notification for it at the given time. My problem is that the \"shownam
Intents are reused in the system, unless they differ on context/action I believe. Documentation Link. That is, if you have already constructed an Intent, that intent might be used later as well.
As a debug-test, you could try to add intent.setAction("" + Math.random())
below intent.putExtras(c)
and see if your extras are received in the other end.
Relevant Documentation:
Because of this behavior, it is important to know when two Intents are considered to be the same for purposes of retrieving a PendingIntent. A common mistake people make is to create multiple PendingIntent objects with Intents that only vary in their "extra" contents, expecting to get a different PendingIntent each time. This does not happen. The parts of the Intent that are used for matching are the same ones defined by Intent.filterEquals. If you use two Intent objects that are equivalent as per Intent.filterEquals, then you will get the same PendingIntent for both of them.
You should use intent.putExtra()
method. Not set bundle to extras segment. IF you set string, you whould intent.putExtra(<key>, value);
Try this it will be done. I used it.
If you change the Extra's value in the intent, then while creating the pending intent you should use the flag PendingIntent.FLAG_CANCEL_CURRENT.
A simple example would be
PendingIntent pi = PendingIntent.getBroadcast(context, 0,intentWithNewExtras,PendingIntent.FLAG_CANCEL_CURRENT);
This is the right way and will ensure that your new values are delivered.
Hope it helps.
I was had same problem. I solved it with setting an action to intent as suggested by @aioobe here, and my intent works like a magic.
Here what i did
` intent.putExtra("Name", mName);
intent.putExtra("dateTime", newdate);
intent.setAction("" + Math.random());`
Hope it will help someone, happy coding..! :)
use different request code for different alarm notifications to avoid overwriting of same alarm time.