Tôi đang cố tạo nhiều thông báo trong ứng dụng của mình. Để xác định từng thông báo duy nhất, tôi đã cung cấp cho họ một ID nhận dạng duy nhất. Sau đây là mã của tôi:Android: Quản lý nhiều thông báo
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);
}
Vấn đề: Khi thông báo được chọn, Hoạt động của tab được gọi là chuyển mục đích. Tôi muốn truy cập vào thông báo duy nhất của thông báo đã được chọn trong Tab. Tôi đã thử intent.putExtra() để lưu thông báoId trong mục đích. Tuy nhiên, đối với nhiều thông báo, nó ghi đè lên notificationId và trả về phiên bản mới nhất. Tôi không hiểu tại sao điều này xảy ra và làm thế nào tôi có thể tránh ghi đè này của notificationId.
Xin cảm ơn, Chander