2013-03-10 2 views
0

La méthode ci-dessous est appelée deux fois avec un paramètre différent name mais seulement 1 notification apparaît sur mon appareil (le dernier). Je pensais que mettre un paramètre de mode de demande unique à l'intérieur PendingIntent.getActivity() avec name.hashCode() fonctionnerait mais cela n'a pas résolu le problème. Alors, comment puis-je modifier cette méthode pour que mon appareil affiche 2 notifications à la suite plutôt que la dernière?Android: Comment puis-je afficher 2 notifications à la suite

private void showNotification(String name, String sub) { 
     Intent intent = new Intent(activity.getApplicationContext(), 
       FragmentTabsPager.class); 
     PendingIntent pIntent = PendingIntent.getActivity(
       activity.getApplicationContext(), name.hashCode(), intent, 0); 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(
       activity.getApplicationContext()); 
     builder.setContentTitle("Hello world" 
       ).setContentText(name+" from "+sub) 
       .setSmallIcon(R.drawable.icon).setContentIntent(pIntent) 
       .getNotification(); 
     NotificationManager notificationManager = (NotificationManager) activity 
       .getApplicationContext().getSystemService(
         Context.NOTIFICATION_SERVICE); 
     Notification notification = builder.getNotification();  
     notification.flags |= Notification.FLAG_AUTO_CANCEL;   
     notification.defaults |= Notification.DEFAULT_SOUND; 
     notification.defaults |= Notification.DEFAULT_VIBRATE;  
     notificationManager.notify(0, notification); 
    } 

Répondre

0

Le premier paramètre à notify() est l'ID de la notification. Cela doit être différent si vous voulez que Notification s apparaissent à l'écran. Si vous appelez le notify() deux fois avec le même ID, le Notification est remplacé, pas ajouté.

Questions connexes