2014-06-26 6 views
6

Ich möchte eine Benachrichtigung erstellen, ohne vorherige Benachrichtigungen aus meiner App zu löschen/löschen. Hier ist mein Code eine Benachrichtigung für die Erstellung von:Android: Nach dem Erstellen einer neuen Benachrichtigung wird der ältere ersetzt

private void notification(Context context, String title, String content) { 
    NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(context) 
      .setSmallIcon(R.drawable.notification_icon) 
      .setContentTitle(title) 
      .setContentText(content); 

    Intent resultIntent = new Intent(context, MainActivity.class); 
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); 
    // Adds the back stack for the Intent (but not the Intent itself) 
    stackBuilder.addParentStack(MainActivity.class); 
    // Adds the Intent that starts the Activity to the top of the stack 
    stackBuilder.addNextIntent(resultIntent); 
    PendingIntent resultPendingIntent = 
      stackBuilder.getPendingIntent(
       0, 
       PendingIntent.FLAG_UPDATE_CURRENT 
      ); 
    mBuilder.setContentIntent(resultPendingIntent); 
    NotificationManager mNotificationManager = 
     (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    //Id allows you to update the notification later on. 
    mNotificationManager.notify(100, mBuilder.build()); 
} 

Antwort

12

Sie sind eine hartcodierte ID für Ihre Mitteilung mit, natürlich wird es die alten zu ersetzen. Versuchen Sie es mit einer Variablen-ID anstelle eines hartcodierten 100.

oder etwas Ähnliches.