如何从活动中逐个显示通知提醒列表?

时间:2011-07-15 10:00:06

标签: android list notifications

我是android应用程序的新程序员我想从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数组值显示为列表

的通知

1 个答案:

答案 0 :(得分:7)

你的问题不是很清楚。我想您正在询问如何显示通知并将其保留,因此当您显示更多通知时,他们不会删除之前的通知。即每次显示通知时,都会将其添加到列表中而不替换现有通知。如果是这样,你就这样做:

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

通过为每个通知提供不同的标识符,它们将单独显示。