Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Managing Multiple Notifications

Tags:

java

android

I am trying to create multiple notifications in my application. To identify each notification uniquely, i have given them an unique identificationId. Following is my 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.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: When a notification is selected, Tabs activity is called passing the intent. I want to access the unique notificationId of the notification that was selected in Tabs. I tried intent.putExtra() to save the notificationId in the intent. But, for multiple notifications its overwriting the notificationId and returns the latest one. I dont understand as to why this is happening and how can i avoid this overwriting of notificationId.

Thanks, Chander

like image 304
Chander Shivdasani Avatar asked Aug 12 '10 06:08

Chander Shivdasani


1 Answers

I got the answer. The intents were getting cached in. To, make a new intent, just add the following piece of code:

saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis())));

This makes the intent unique.

Also, someone suggested me the following piece of code to make the intent unique:

saveCallIntent.setAction("actionstring" + System.currentTimeMillis());

It didnt help me, but might be of help to someone else.

--Chander

like image 194
Chander Shivdasani Avatar answered Sep 18 '22 00:09

Chander Shivdasani