android - getString from Bundle loses old value -


from firstactivity i'm creating 3 seperate notifications , on clicking them start secondactivity in same application. issue value of string in secondactivity last notification posted. need start secondactivity , display call notification 1 when click on notification id =1 , id = 2 , id =3. i'm losing put extras in intent object. please me if have come across such situation before. i've tried pendingintent flag flag_cancel_current in vain. in advance. :-)

notificationmanager nm; notification n; pendingintent pi1, pi2, pi3; button btnnotify1, btnnotify2, btnnotify3; intent intent;  final static string ticker_text = "my_notification";  @override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_notification);      btnnotify1 = (button) findviewbyid(r.id.btnnotify1);     btnnotify2 = (button) findviewbyid(r.id.btnnotify2);     btnnotify3 = (button) findviewbyid(r.id.btnnotify3);      nm = (notificationmanager) getsystemservice(context.notification_service);      n = new notification(r.drawable.ic_launcher, ticker_text,         system.currenttimemillis());     n.flags = n.flags | notification.flag_auto_cancel;      intent = new intent(this, secondactivity.class);     intent.setflags(intent.flag_activity_clear_top);      btnnotify1.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {              intent.putextra("call_is_from", "notification 1");             pi1 = pendingintent.getactivity(getapplicationcontext(), 0,                 intent, pendingintent.flag_update_current);             n.setlatesteventinfo(getapplicationcontext(), "notification 1",                 "one", pi1);             nm.notify(1, n);          }     });     btnnotify2.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {              intent.putextra("call_is_from", "notification 2");             pi2 = pendingintent.getactivity(getapplicationcontext(), 0,                 intent, pendingintent.flag_update_current);             n.setlatesteventinfo(getapplicationcontext(), "notification 2",                 "two", pi2);             nm.notify(2, n);          }     });     btnnotify3.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {              intent.putextra("call_is_from", "notification 3");             pi3 = pendingintent.getactivity(getapplicationcontext(), 0,                 intent, pendingintent.flag_update_current);             n.setlatesteventinfo(getapplicationcontext(), "notification 3",                 "three", pi3);             nm.notify(3, n);          }     }); } 

you need make sure each of pendingintents unique. since getting pendingintent using same intent , same requestcode, same pendingintent (even though extras different).

to make sure each of pendingintents unique, use different requestcode each, this:

pi1 = pendingintent.getactivity(getapplicationcontext(), 1,             intent, pendingintent.flag_update_current);  pi2 = pendingintent.getactivity(getapplicationcontext(), 2,             intent, pendingintent.flag_update_current);  pi3 = pendingintent.getactivity(getapplicationcontext(), 3,             intent, pendingintent.flag_update_current); 

Comments