Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android pending intent notification problem

I have a alarm thing going on in my app and it launches a notification that then when pressed launched an activity. The problem is that when I create more than one alarm then the activity launched from the notification gets the same extras as the first one. I think the problem is either with the intent i put in the pending intent or in the pending intent itself. I think I might need to put a flag on one of these but I dont know which one.

Intent showIntent =new Intent(context, notificationreceiver.class);     showIntent.putExtra("details", alarmname);  PendingIntent contentIntent = PendingIntent.getActivity(context, 0,         showIntent, 0);       notification.setLatestEventInfo(context, "The event is imminent",             alarmname, contentIntent); 

And the receiver of the notification

Bundle b = getIntent().getExtras();     String eventname = b.getString("details");     details.setText(eventname); 

The "details" extra is the same to every the next time a notification happens instead of having the different value. Until I set the intents I am sure that the correct value goes to the "details" so its a problem of getting the first intent everytime i press any notification. How can I make it to launch the correct intents? Hope I was as clear as i could Thanks!

like image 806
spagi Avatar asked Jun 09 '10 19:06

spagi


People also ask

What is pending intent in Android notification?

Android PendingIntent In other words, PendingIntent lets us pass a future Intent to another application and allow that application to execute that Intent as if it had the same permissions as our application, whether or not our application is still around when the Intent is eventually invoked.

Which intent is used for sending notification in Android?

MainActivity. The NotificationManager. notify() method is used to display the notification. The Intent class is used to call another activity (NotificationView.


1 Answers

The way I solved that problem was by assigning a unique requestCode when you get the PendingIntent:

PendingIntent.getActivity(context, requestCode, showIntent, 0);  

By doing so you are registering with the system different/unique intent instances. Tip: A good way of making the requestCode unique would be by passing to it the current system time.

int requestID = (int) System.currentTimeMillis(); 
like image 96
u-ramos Avatar answered Nov 15 '22 14:11

u-ramos