0

I have included a unique id for creating PendingIntent as well as in mNM.notify() method. When I set two notifications to display at the same time they do not get displayed simultaneously. The first notification get displayed with the time given for the second notification. Many people have had this problem and the only suggestion was to give unique IDs. But that doesn't work! Please Help. Below is my showNotification() method.

private void showNotification() {
    /*create intent for show notification details when user clicks notification*/
    Intent intent =new Intent(getApplicationContext(), MainActivity.class);
    Random random = new Random();
    int id = random.nextInt();
    intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
    // This is the 'title' of the notification
    CharSequence title = "Reminder!" + id;
    // This is the icon to use on the notification
    int icon = R.drawable.ic_dialog_alert;
    // This is the scrolling text of the notification
    CharSequence text = task;       
    // What time to show on the notification
    long time = System.currentTimeMillis();
    Notification notification = new Notification(icon, text, time);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this,id, intent, Intent.FLAG_ACTIVITY_NEW_TASK);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, title, text, contentIntent);

    // Clear the notification when it is pressed
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Send the notification to the system.
    mNM.notify((int)System.currentTimeMillis(), notification);

    // Stop the service when we are finished
    stopSelf();
}
Gayan Jayasingha
  • 752
  • 2
  • 17
  • 33
  • You don't need `getApplicationContext()`; use `this`. I have no idea what that `custom://` is supposed to be doing. You really should consider using `Notification.Builder` or `NotificationCompat.Builder` rather than rolling a `Notification` by hand. `Intent.FLAG_ACTIVITY_NEW_TASK` is not a valid flag for `getActivity()` on `PendingIntent`. And showing two `Notifications` is usually not a good idea in the first place -- show one `Notification` with details about the multiple events. – CommonsWare Apr 25 '14 at 20:12
  • I concur you should be using the builder and two notifications is an anti-pattern. Specifically an app should have one notification that tells how many notifications are pending But there's nothing wrong with being an individual when you develop so keep on going. I'm actually planing on a color notification which is also a direct violation of `[design pattern for notifications.](http://developer.android.com/design/patterns/notifications.html) – danny117 Apr 25 '14 at 20:43

1 Answers1

0

I haven't tried this unsupported answer.

I think your looking for the .setOngoing(true) The user can't cancel this notification so I imagine the OS can't cancel it either.

danny117
  • 5,581
  • 1
  • 26
  • 35