Android: managing multiple status bar notifications

I am creating an application with several stopwatch, for which several timers will be executed, and each notification is attached to each timer.

I can create multiple timers with the following code.

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.setClassName("com.intuit.time_catcher.android.activities", "com.intuit.time_catcher.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); } 

Below is the problem im is facing. Think there are 3 timers and 3 notifications in the status bar. When I update timer 2, notification 3 (which is on the very right end) is updated, but I really want to do this to update the second notification (middle). When I print the notification ID, I see the correct values. I can’t understand why I get this strange behavior?

+6
java android
source share
2 answers

It looks like your intentions are cached (this is the factory by default)

Try adding a unique setAction('anystring'+timestamp) or a count value, it should be unique as described in this question

 intent.setAction("actionstring" + System.currentTimeMillis()); 
+4
source share

The app cannot directly control the order notifications that appear ... do you just see that they are redirected to you?

Also posting three notifications is pretty spam. How about having one whose contents show the status of all three timers?

+1
source share

All Articles