views:

97

answers:

2

I'm sending a C2DM update to my Android app every 1/2 hour, which creates a Notification. Problem is, when I wake up in the morning I get 15 Notifications queued up in the status bar.

How do I only keep the latest notification, overwriting previous ones?

I tried looking at the C2DM documentation (http://code.google.com/android/c2dm/) which mentions a parameter called collapse_key, but I couldn't find an explanation for how to use it, nor am I sure the solution lies on the C2DM side.

Thanks!

+1  A: 

If you want to cancel any previous notifications that has been set on the view you can try setting one of these flags.

PendingIntent.FLAG_CANCEL_CURRENT or  PendingIntent.FLAG_UPDATE_CURRENT 

Something like this should replace your old notification i believe

 NotificationManager mManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 Intent intent = new Intent(this,test.class);
 Notification notification = new Notification(R.drawable.icon, "Notify", System.currentTimeMillis());
 notification.setLatestEventInfo(this,"App Name","Description of the notification",
 PendingIntent.getActivity(this.getBaseContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
 mManager.notify(0, notification);
Rahul
+1  A: 

Notification has a property called number that shows a little number below the icon (for multiple notification). It lets you use the same Icon for Multiple Notification.

Use the same ID while updating your notification. :) Cheers.

st0le
Accepting Rahul's answer because it answered to my original question, but I definitely used the number property as well-- thanks for the tip!
yayitswei
@yayitswei, that's fine, i framed my answer as an addition to Rahul's answer.
st0le