How to remove the notification after the particular time in android?
The current correct solution may be to use:
NotificationCompat.Builder#setTimeoutAfter(long)
AlarmManager is more often used for complicated Services that have to run in the Background when the Application is closed. You could also use a classic Java Runnable in a Handler for a simple small Thread.
Handler h = new Handler();
long delayInMilliseconds = 5000;
h.postDelayed(new Runnable() {
public void run() {
mNotificationManager.cancel(id);
}
}, delayInMilliseconds);
Also look here:
Clearing notification after a few seconds
You could also use the TimerTask-Class.
What you need is a combination of Alarmmanager and notificationmanger.
Register the alarm manager that will call a service in 5 minutes and use NotificationManager.cancel in the service implementation.
Alarm Service Sample is here. I suppose you know to use Notification Manager.