我有一项活动,通过按钮按钮启动服务。在服务初始化,如果发生错误,被通知显示此错误,如下所示:为什么通知会打开另一个活动实例?
String tickerText = getString(R.string.init_error);
Notification notification = new Notification(
R.drawable.ic_stat_notify_msg,
tickerText, System.currentTimeMillis());
PendingIntent notificationIntent = PendingIntent.getActivity(
this, 0, new Intent(this, MyServiceActivity.class), 0);
notification.setLatestEventInfo(this,
getText(R.string.init_error_tts_title),
getText(R.string.init_error_tts_text),
notificationIntent);
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
nm.notify(R.string.init_error, notification);
stopSelf();
当通知出现在状态栏上,我打开通知窗口。然后,当我点击通知时,会启动MyServiceActivity的新实例...为什么?
'singleTop'是你想要的。 – techiServices
是的,当然,这就是为什么我通过Doc完成我的答案链接 – ChristopheCVB
太棒了!有用! – enzom83