Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display list of notification alerts one by one from activity?

i am new programmer in android application i would like display multiple notifications one by one from activity.i have implemented a method to get the notification as follows

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



}

and i have used a string array to display the notifications as a list the following code for display notifications

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

from above code i would like to display notifications alerts list one by one as follows:

hai

how are you?

wer r u?

what is going on

how is this?

........

how can i display the String array values as notifications as list

like image 784
prasad.gai Avatar asked Jul 15 '11 10:07

prasad.gai


People also ask

How do I see stacked notifications IOS?

Unless you have notifications silenced with a Focus, iPhone displays them as they arrive—they roll in from the bottom of the screen to minimize distraction. You can view them on the Lock Screen in an expanded list view, stacked view, or count view. Pinch the notifications on the Lock Screen to change the layout.

How do I show multiple notifications on Android?

Set the unique id to let Notification Manager knows this is a another notification instead of same notification. If you use the same unique Id for each notification, the Notification Manager will assume that is same notification and would replace the previous notification.

How can I see all my notifications on iPhone?

Notification Center shows your notifications history, allowing you to scroll back and see what you've missed. There are two ways to see your alerts from the Notification Center: From the Lock Screen, swipe up from the middle of the screen. From any other screen, swipe down from the center of the top of your screen.


1 Answers

Your question isn't very clear. I think you are asking how you can show notifications and have them remain, so as you show more notifications they do not remove the previous ones. i.e. each time you show a notification it's added to the list without replacing the existing one. If so, you do that like this:

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

By providing a different identifier to each notification, they are displayed separately.

like image 53
Ollie C Avatar answered Oct 23 '22 02:10

Ollie C