Ich versuche, mehrere Benachrichtigungen in meiner Anwendung zu erstellen. Um jede Benachrichtigung eindeutig zu identifizieren, habe ich ihnen eine eindeutige ID gegeben. mein Code finden:Android: Verwalten mehrerer Benachrichtigungen
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);
}
Problem: Wenn eine Benachrichtigung aktiviert ist, Tabs Aktivität aufgerufen, um die Absicht vorbei. Ich möchte auf die eindeutige notificationId der Benachrichtigung zugreifen, die in Tabs ausgewählt wurde. Ich versuchte intent.putExtra(), um die notificationId in der Absicht zu speichern. Bei mehreren Benachrichtigungen überschreibt er die notificationId und gibt die neuste zurück. Ich verstehe nicht, warum das passiert und wie kann ich dieses Überschreiben von notificationId vermeiden.
Danke, Chander