2011-07-15 32 views
5

我在機器人應用我想顯示多個通知逐個從activity.i新程序員已經實現的方法,以獲得通知如下如何從活動中逐一顯示通知警報列表?

 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); 



} 

和我已經使用一個字符串數組,以顯示通知作爲列表進行顯示的通知下面的代碼

 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(); 

從上面的代碼我想通過一個顯示通知的警報列表中的一個,如下所示:

你好嗎?

wer r u?

發生了什麼

這是怎麼回事?

........

我怎麼能顯示String數組值通知作爲名單

回答

7

你的問題不是很清楚。我想你是問你如何顯示通知並讓它們保持不變,所以當你顯示更多的通知時,他們不會刪除以前的通知。即每次顯示通知時,都會將其添加到列表中,而不會替換現有的通知。如果是這樣,你這樣做:

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

通過爲每個通知提供一個不同的標識符,它們分開顯示。