Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Notification Id in android

Tags:

android

I am making an app based on notification in which I had implemented Notification code but in that code I want to about notification Id .what is that can any body explain me .

code:-

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setContentTitle("This is a notification");
    mBuilder.setSmallIcon(R.drawable.app_me);
    mBuilder.setContentText("You have successfully created notification");

    Intent resultIntent = new Intent(this,ResultActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(ResultActivity.class);

    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPending = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPending);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // notificationID allows you to update the notification later on.
    notificationManager.notify(notificationID, mBuilder.build());
like image 822
Satish Avatar asked Sep 21 '16 04:09

Satish


2 Answers

When you need to issue a notification multiple times for the same type of event, you should avoid making a completely new notification. Instead, you should consider updating a previous notification. For that you need NotificationID. Notification can be updated, issue it with a notification ID by calling Check here, https://developer.android.com/training/notify-user/managing.html

like image 91
Mujammil Ahamed Avatar answered Oct 07 '22 12:10

Mujammil Ahamed


Its a numeric id that you get to define. If you later want to change this notification, you can specify the same notification id and it will change the original notification (or cancel it if you want) rather than create a new one.

like image 43
Gabe Sechan Avatar answered Oct 07 '22 11:10

Gabe Sechan