点击应用程序时会发出通知

时间:2012-02-02 14:49:27

标签: android

我想发出通知,点击它会将我的应用从背景带到前面。我使用以下代码:

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);

当我点击发出新意图的通知但我想将最后创建的意图带到前面时。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

您需要在传递给getActivity的intent上设置FLAG_ACTIVITY_SINGLE_TOP标志。 这会在您点击通知时返回到所有准备就绪的活动。

请参阅here以获取不同启动标志的列表。

答案 1 :(得分:0)

试试这个

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