android - Set/Get Extras in Multiple Instances of Notification -


i have android notification sent id destination activity. that, use intent putextra this:

intent resultintent = new intent(this.context, confirmationactivity.class);  resultintent.putextra("id", idtosent);  resultintent.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task);  resultpendingintent = pendingintent.getactivity(this.context, 0, resultintent, pendingintent.flag_update_current); 

the problem when call notification 2, 3 or more time. when use "getextras" in method oncreate of activity, have same id (the last id sent last notification instance)

i had try changing intent's flags, can't find right combination

can me this?

how have, lets say, 3 instances of notification , when click on notification, sent 3 diferents id activity?

this full code:

//notification manager class

public void sendnearpromotionnotification(int idtosent){      notificationcompat.builder notificationbuilder = new notificationcompat.builder(this.context);      notificationbuilder.setcontenttitle(context.getresources().getstring(r.string.title));     notificationbuilder.setcontenttext(context.getresources().getstring(r.string.text));     notificationbuilder.setticker(context.getresources().getstring(r.string.ticket));     notificationbuilder.setsmallicon(r.drawable.icon);      int apilevel = integer.valueof(android.os.build.version.sdk_int);      pendingintent resultpendingintent = null;         if (apilevel < build.version_codes.jelly_bean){               intent resultintent = new intent(this.context, confirmationactivity.class);          resultintent.putextra("id", idtosent);          resultintent.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_task);          resultpendingintent = pendingintent.getactivity(this.context, 0, resultintent, pendingintent.flag_update_current);      }else{          intent addwishlistintent = new intent(this.context,  intentservicenotifications.class);          addwishlistintent.putextra("id", idtosent);          pendingintent pendingintent = pendingintent.getservice(this.context, 0, addwishlistintent, pendingintent.flag_cancel_current);          notificationbuilder.addaction(r.drawable.icon2, "add wishlist", pendingintent);     }      notificationbuilder.setautocancel(true);      notificationbuilder.setcontentintent(resultpendingintent);      notificationmanager notificationmanager = (notificationmanager)this.context.getsystemservice(context.notification_service);      notificationmanager.notify(idtosent, notificationbuilder.build()); } 

//confirmationactivity class

public class promotionconfirmationactivity extends fragmentactivity {      private int id = 0;      @override     protected void oncreate(bundle savedinstancestate) {          settheme(android.r.style.theme_translucent_notitlebar);          super.oncreate(savedinstancestate);          setcontentview(r.layout.layout_transparent);          bundle extras = getintent().getextras();          if(extras != null)             id = extras.getint("id");     } } 

try this:

    private static class idgenerator {           private static final atomicinteger counter = new atomicinteger();           public static int nextvalue() {              return counter.getandincrement();          }     }       ...      resultpendingintent = pendingintent.getactivity(this.context, idgenerator.nextvalue(), resultintent, pendingintent.flag_cancel_current); 

the documentation claims id sent second parameter not used, in fact needed these kind of purposes.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -