我想在我的應用程序中創建多個通知。爲了唯一標識每個通知,我給了他們一個唯一的身份標識。以下是我的代碼:Android:管理多個通知
private void updateNotification(int notificationId, int clockStatusID, CharSequence text) {
//notificationManager.cancel(notificationId);
// throws up an ongoing notification that the timer is running
Log.i("TIMERCOUNT", "Notification id: " + notificationId);
Notification not = new Notification(clockStatusID, // the
// icon
// for
// the
// status
// bar
text, // the text to display in the ticker
System.currentTimeMillis() // the timestamp for the
// notification to appear
);
Intent intent = new Intent();
intent.putExtra("notificationID", notificationId);
intent.setAction("actionstring" + System.currentTimeMillis());
intent.setClassName("com.chander.time.android.activities",
"com.chander.time.android.activities.Tabs");
not.setLatestEventInfo(self,
getText(R.string.timer_notification_title),
getText(R.string.timer_on_notification_text), PendingIntent
.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT));
not.flags += Notification.FLAG_ONGOING_EVENT;
not.flags += Notification.FLAG_NO_CLEAR;
notificationManager.notify(notificationId, not);
}
問題: 當選擇了一個通知,標籤活動被稱爲合格的意圖。我想要訪問在選項卡中選擇的通知的唯一通知ID。我嘗試了intent.putExtra()來保存意圖中的notificationId。但是,對於多個通知,它將覆蓋notificationId並返回最新的通知。我不明白爲什麼會發生這種情況,我如何避免這種覆蓋notificationId。
感謝, 錢德爾