I’ve an alarmreceiver that fire a notification from broadcast. Runs perfectly. Now I added another notification and I like have 2 notifications indipendently. Starts first notification, later starts second notification, second notification cancel the first notification so I see only second. I need have 2 notification on notification bar. Also remove “flag cancel” does not runs.
My code (second notification):
String ns2 = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager2 = (NotificationManager) context.getSystemService(ns2);
int icon = R.drawable.ic_launcherlight;
CharSequence tickerText = not1[x];
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "Casual";
CharSequence contentText = not1[x];
Intent notificationIntent = new Intent("com.example.myapp", null, context, NotifyCasual.class);
notificationIntent.putExtra("notify", not1[x]);
PendingIntent contentIntent = PendingIntent.getActivity(context, 2, notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String Sound = prefs.getString("sound", "");
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
final int HELLO2 = 1;
mNotificationManager2.notify(HELLO2, notification);
You have to do like this.
When you are creating notification just follow this.
For 1st notification:
For 2nd notification: