Published on Sep 30,2014
Email Post

Notification on Android is an important part of the Android Operating System. It contains a class to use notification called the “Notification Manager” to use the notification services. We use a “PendingIntent” used to register for device in memory. We create an “intent” with the application that does not need an activity to be launched. They are the ones running with the system.

An example would be alarms in the device for waking up in the morning. But if the user sets an alarm, how does the system know when to sound the alarm. Here, it registers a pending intent with the application so that whenever we raise the alarm the “PendingIntent” will notify the user.

Another example is the notification on change of time zone when travelling. We can receive the activity via the code:


Notification Extras

We use a “Notification.Builder” which allows to define actions to the notification. A “PendingIntent” itself is simply  a reference to a token maintained by the system. This also means that even if its own application process is killed, the “PendingIntent” itself will remain usable from other processes.

Whenever we associate a “PendingIntent” then we have a reference of association with the Android System which means that any application that is closed post-registration with the “PendingIntent”, it will still remain reusable.

Here, we call the “NotificationClickedActivity.Java” which displays the text view.

As we work on the notification part in Java, we observe the following code:

Public class Notification extends Activity {
Button btnNotification;
We then create an Intent
Intent Intent = new Intent (Notifications.this,

Then we create a “PendingIntent”

PendingIntent pendIntent = PendingIntent.getActivity(
Notifications.this, 0, intent, 0);

It creates a context, request code, intent to launch the activity and flags where we can associate choices between various flags.

We then call a Notification object to build the notification for the user through the code:

Notifications notiMail = new Notification.Builder{

The content title, content text, small icon and the content intent is set.

We finally call the “build” once the notification is ready. We call the “Notification Manager” and ask it to notify using notification mail. Also note, it take integer identifier while executing the program.

Once we execute the program, we view the following output:

Once the notification is clicked, it will open the launching activity. We can also go back to generate the notification again.

Got a question for us? Mention them in the comments section and we will get back to you.

Related Posts:

Beginner’s Guide to Android Architecture

Android Development Course

About Author
Published on Sep 30,2014

Share on

Browse Categories