java - start NEW Activity from PendingIntent with unique extra -


i trying "read more" after user click on notification.

what need, start new activity unique content "id", "title" , "text".

my code:

void notificationsend(string id, string bar, string title, string text, string image, int delay) {     bitmap bitmap = getbitmapfromurl(image, 130);      if(bitmap == null){         bitmap = getbitmapfromurl("https://pp.vk.me/c621316/v621316641/119d5/hb9s2z5mx-s.jpg", 130);     }      intent notificationintent = new intent(this, singlenewsactivity.class);     notificationintent.putextra("id", id);     notificationintent.putextra("title", title);     notificationintent.putextra("text", text);      notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top);      pendingintent contentintent = pendingintent.getactivity(this, 0, notificationintent, pendingintent.flag_update_current);      notificationcompat.builder builder = new notificationcompat.builder(this);      builder.setcontentintent(contentintent);     builder.setsmallicon(r.drawable.ic_bitcoin_notification);     builder.setlargeicon(bitmap);     builder.setticker(bar);     builder.setcontenttitle(title);     builder.setcontenttext(text);     builder.setwhen(system.currenttimemillis());     builder.setsound(ringtonemanager.getdefaulturi(ringtonemanager.type_notification));       notification notification = builder.build();     notification.flags |= notification.flag_auto_cancel;      try {         notificationmanager.notify(new integer(id), notification);         sleep(2000);     } catch (interruptedexception e) {         e.printstacktrace();     } } 

and next thing, lets send 2 notifications, after click on first, activity started data second notification, why?

the issue due using : flag_update_current

if see document flag:

flag indicating if described pendingintent exists, keep replace data in new intent. use getactivity(context, int, intent, int), getbroadcast(context, int, intent, int), , getservice(context, int, intent, int). can used if creating intents extras change, , don't care entities received previous pendingintent able launch new extras if not explicitly given it. 

in case, updating , due that, value of extras updated.

for solution of issue, should pass request code unique case:

currant code:

pendingintent.getactivity(this, 0, notificationintent, pendingintent.flag_update_current); 

actual:

pendingintent.getactivity(this, unique_code, notificationintent, pendingintent.flag_update_current); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -