Bringoff
Bringoff

Reputation: 99

How can I show notification which will be removed after some time?

I need to show a lot of notifications to StatusBar. But in order to not to fill up statusbar with my messages I have to automatically remove notification after 1 minute, for example. How can I do this?

Upvotes: 0

Views: 267

Answers (2)

Bringoff
Bringoff

Reputation: 99

I did it with Timer:

    Notification notification = nb.build();

    notifManager.notify(id, notification);

    final Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            notifManager.cancel(id);
            timer.cancel();
        }
    }, REMOVE_TIME, 1000);

Upvotes: 0

Praveena
Praveena

Reputation: 6941

Follow these steps

  1. Create notification and create Alarm for required duration
  2. Cancel the notification using NotificationManager.cancel(id) in BroadcastRecevier of Alarm

Upvotes: 1

Related Questions