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

pra*_*gai 5 notifications android list

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



}
Run Code Online (Sandbox Code Playgroud)

我已经使用字符串数组将通知显示为列表,显示以下代码用于显示通知

       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();
Run Code Online (Sandbox Code Playgroud)

从上面的代码我想逐个显示通知警报列表如下:

你好吗?

你好吗?

到底是怎么回事

这怎么样?

........

如何将String数组值显示为列表通知

Oll*_*e C 7

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

notificationManager.notify(0, notification);
notificationManager.notify(1, notification);
notificationManager.notify(2, notification);
notificationManager.notify(3, notification);
Run Code Online (Sandbox Code Playgroud)

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