Android 单击应用程序前置时发出通知

Android 单击应用程序前置时发出通知,android,Android,我想做一个通知,当点击它会把我的应用程序从后台带到前台。我正在使用以下代码: NotificationManager noma = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent, 0); intent.putExtra("key", "trigerred"); String body

我想做一个通知,当点击它会把我的应用程序从后台带到前台。我正在使用以下代码:

NotificationManager noma = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent, 0);
intent.putExtra("key", "trigerred");
String body = "This is a message";
String title = "This is title";
Notification no = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis());
no.defaults = Notification.DEFAULT_ALL;
no.setLatestEventInfo(this, title, body, pen);
noma.notify(uniqueID, no);

当我点击发出新意图的通知时,但我希望最后创建的意图显示在最前面。如何做到这一点?

您需要在传递给getActivity的意图上设置FLAG\u ACTIVITY\u SINGLE\u TOP标志。 单击通知时,这将使您返回到“准备就绪”运行活动

有关不同启动标志的列表,请参阅。

试试这个

PendingIntent pen = PendingIntent.getActivity(Timer.this, 0, intent,Intent.FLAG_ACTIVITY_TASK_ON_HOME);

可能重复的邮政编码,你得到你的意图对象。看到答案,我这样做,但它不起作用。请给我举个例子好吗?抱歉,重读文档我认为您需要设置标志\活动\新任务标志。此标志会将活动启动到新任务中,但如果存在此活动已准备就绪的任务,则会将其带到前台。