我提出了一个通知。我想要的是,当用户点击通知时,我的活动被带到前面而不创建它的新实例。为此,我添加了标志 REORDER_TO_FRONT,但当我单击通知时,仍然调用 oncreate 而不是 onNewIntent。
这是我的代码 -
int icon = R.drawable.android;
long when = System.currentTimeMillis();
CharSequence text = "new message";
CharSequence contentTitle = stanza.getFrom(); // message title
CharSequence contentText = stanza.getBody(); // message text
Intent notificationIntent = new Intent(context, ChatBox.class);
notificationIntent.putExtra("buddyid",stanza.getFrom());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, text, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1,notification);