我正在通过这个代码创建一个BroadcastReceiver内部通知:通知通过老意图额外
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = R.drawable.ic_stat_notification;
CharSequence tickerText = "New Notification";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_VIBRATE;
long[] vibrate = {0,100,200,200,200,200};
notification.vibrate = vibrate;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(context, NotificationActivity.class);
notificationIntent.putExtra(Global.INTENT_EXTRA_FOO_ID, foo_id);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
int mynotification_id = 1;
mNotificationManager.notify(mynotification_id, notification);
当我点击该通知,它打开NotificationActivity和活动中,我可以检索的意图foo_id捆绑(例如1)
但是,如果另一个通知被触发,我再次点击它,该活动仍然收到来自意向捆绑的“旧”值(1)。我尝试用clear()清除捆绑包,但收到相同的效果。我认为......我的代码有问题..
请你能告诉我你是怎么从挂起的意图 – user49557
认识到,它是发送旧演员,让我更容易优先分配获取数据。 –