push notification - putExtra using pending intent not working -


i have written code in gcmintentservice sends push notifications many users. use notificationmanager call descriptionactivity class when notification clicked. send event_id form gcmintentservice descriptionactivity

protected void onmessage(context ctx, intent intent) {      message = intent.getstringextra("message");      string tempmsg=message;      if(message.contains("you"))      {         string temparray[]=tempmsg.split("=");         event_id=temparray[1];      }     nm= (notificationmanager)getsystemservice(notification_service);     intent = new intent(this, descriptionactivity.class);     log.i("the event id in service is",event_id+"");     intent.putextra("event_id", event_id);     intent.putextra("gcmevent",true);     pendingintent pi = pendingintent.getactivity(this,0, intent, 0);     string title="event notifier";     notification n = new notification(r.drawable.defaultimage,message,system.currenttimemillis());     n.setlatesteventinfo(this, title, message, pi);     n.defaults= notification.default_all;     nm.notify(uniqueid,n);     sendgcmintent(ctx, message);  } 

here event_id i'm getting in above method correct i.e updated one. in code below (descriptionactivity.java):

    intent = getintent();     final bundle b = intent.getextras();     event_id = integer.parseint(b.getstring("event_id")); 

the event_id here "5". no matter putextra in gcmintentservice class,the event_id 5. can please point out problem? is because of pending intent? if yes, how should handle it?

the pendingintent reused first intent provided, that's problem.

to avoid this, use flag pendingintent.flag_cancel_current when call pendingintent.getactivity() new one:

pendingintent pi = pendingintent.getactivity(this, 0, intent, pendingintent.flag_cancel_current); 

alternatively, if want update extras, use flag pendingintent.flag_update_current


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -