【发布时间】:2013-11-25 21:53:19
【问题描述】:
所以我的状态栏中有一个通知,当用户单击该通知时,会显示一个没有标题的活动,以复制一个对话框。但我有一个问题。如果我打开应用程序,只需单击主页按钮,然后单击状态栏中的通知。它显示了应用程序的主要活动,通知活动堆叠在顶部。我想要做的是,当我点击通知时,它会清除所有底部活动,这样就不会发生。这是我用来启动通知活动的代码
// Send Notification
Intent intent1 = new Intent(this, Dialog.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent1, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_quick_tweet_icon)
.setContentTitle("Dialog")
.setContentText("Touch for more options")
.setWhen(System.currentTimeMillis())
.setContentIntent(pIntent)
.setAutoCancel(false).setOngoing(true);
NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = builder.getNotification();
nm.notify(1, notif);
【问题讨论】:
-
你可以在离开时使用
finish()一个活动,这样会更容易
标签: android android-intent android-activity notifications