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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -