您好,我已经成功地在我的应用中显示了通知,但当用户点击通知时,应用程序会重新启动。然而,我只想让它重新出现而不是重新启动。例如,它是一个Web应用程序,当用户选择通知时,我希望它出现在前面,但不要刷新Web页面。我是否可以捕捉此意图,或者我发送了错误的意图?通常,如果我按下主页按钮并单击应用程序图标,应用程序会出现在前面,而不会刷新/重新启动。所以这就是我想要的行为。有什么建议吗?
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
//2.Instantiate the Notification
int icon = R.drawable.notification_icon;
CharSequence tickerText = "My App"; // temp msg on status line
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
//3.Define the Notification's expanded message and Intent:
Context context = getApplicationContext();
CharSequence contentTitle = "Notification";
CharSequence contentText = "My app!"; // message to user
Intent notificationIntent = new Intent(this, HelloAndroid2.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
//4.Pass the Notification to the NotificationManager:
final int NOTIFICATION_ICON_ID = 1;
mNotificationManager.notify(NOTIFICATION_ICON_ID, notification);