Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Managing multiple notifications in status bar

Tags:

java

android

I am creating a multiple stop watch application for which there will be multiple timers running parallel, and each notification binded to each timer.

I am able to 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);

}

The following is the problem that im facing. Consider there are 3 timer running and 3 notifications in the status bar. When i update timer 2, notification 3(which is at the rightmost end) gets updated, but what i really want to do is to update the second notification(middle one). When i print the notification id's, im seeing the right values. I cant comprehend why am i getting this weird behavior?

like image 303
Chander Shivdasani Avatar asked Aug 06 '10 21:08

Chander Shivdasani


People also ask

How do I manage multiple notifications on Android?

Set the unique id to let Notification Manager knows this is a another notification instead of same notification. If you use the same unique Id for each notification, the Notification Manager will assume that is same notification and would replace the previous notification.

How can I customize my Android status bar?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.

How do I stack notifications on Android?

To create a stack, call setGroup() for each notification you want in the stack and specify a group key. Then call notify() to send it to the wearable. final static String GROUP_KEY_EMAILS = "group_key_emails"; // Build the notification, setting the group appropriately Notification notif = new NotificationCompat.


2 Answers

It sounds like your intents are cached (which is the factory default)

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

intent.setAction("actionstring" + System.currentTimeMillis());
like image 120
Pentium10 Avatar answered Oct 12 '22 22:10

Pentium10


An application can't really directly control the order notifications are shown in... are you just seeing them re-ordered on you?

Also posting three notifications is pretty spammy. What about having one, whose content shows the state of all 3 timers?

like image 34
hackbod Avatar answered Oct 13 '22 00:10

hackbod