2011-07-15 9 views
5

soy nuevo programador de aplicaciones para Android me gustaría visualización múltiples notificaciones uno a uno de activity.i han implementado un método para obtener la notificación de la siguiente maneracómo mostrar la lista de alertas de notificación una por una de la actividad?

 public void myNotify(String message) { 

    Log.v("my notification method","from GetNotification class"); 

    NotificationManager notificationManager = (NotificationManager)  getSystemService(NOTIFICATION_SERVICE); 
    Notification notification = new Notification(R.drawable.icon, 
      "check the notification", System.currentTimeMillis()); 
    // Hide the notification after its selected 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("")); 
    PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0); 
    notification.setLatestEventInfo(this, message, 
      "for more info run ur app", activity); 
    notification.number += 1; 
    notificationManager.notify(0, notification); 



} 

y he utilizado una matriz de cadenas para mostrar las notificaciones como una lista el siguiente código para mostrar las notificaciones

 String[] msg={"hai","how are you?","wer r u?","what is going on","how is this?","let we talk?","nothing is there","hahaha"}; 
    Thread rt=new Thread(new Runnable() { 

     @Override 
     public void run() { 

      try { 

       for(int i1=0;i1<msg.length;i1++){ 

        Log.v("", "thread running"+i1); 

        myNotify(msg[i1]); 

        Thread.sleep(5000); 
       } 
      } catch (InterruptedException e) { 

       e.printStackTrace(); 
      } 
     } 
    }); 

    rt.start(); 

desde arriba código que le gustaría mostrar la lista de notificaciones de alertas uno por uno de la siguiente manera:

Hai

¿cómo estás?

wer r u?

¿Qué está pasando

cómo es esto?

........

cómo puedo mostrar los valores de matriz de cadenas como notificaciones como lista

Respuesta

7

Su pregunta no es muy clara. Creo que estás preguntando cómo puedes mostrar las notificaciones y que se queden, así que a medida que muestras más notificaciones no eliminan las anteriores. es decir, cada vez que muestra una notificación, se agrega a la lista sin reemplazar la existente. Si es así, lo haces de esta manera:

notificationManager.notify(0, notification); 
notificationManager.notify(1, notification); 
notificationManager.notify(2, notification); 
notificationManager.notify(3, notification); 

Al proporcionar un identificador diferente para cada notificación, se muestran por separado.

Cuestiones relacionadas