所以我有一個通知在我的狀態欄,當用戶點擊時提出了一個沒有標題的活動,以複製一個對話框。但我有一個問題。如果我打開應用程序,那麼只需單擊主頁按鈕,然後單擊狀態欄中的通知即可。它將堆疊在頂部的notificato活動展示在應用程序的主要活動中。我想要做的就是這樣做,當我點擊通知時,它會清除所有底部的活動,以免永遠不會發生。這裏是我用來啓動通知活動的代碼清除舊的活動,使他們不會出現在新的活動點擊
// 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()'一個活動,這會更容易 – chinglun