Javatpoint Logo
Javatpoint Logo

Android Notification

Android Notification provides short, timely information about the action happened in the application, even it is not running. The notification displays the icon, title and some amount of the content text.

Set Android Notification Properties

The properties of Android notification are set using NotificationCompat.Builder object. Some of the notification properties are mention below:

  • setSmallIcon(): It sets the icon of notification.
  • setContentTitle(): It is used to set the title of notification.
  • setContentText(): It is used to set the text message.
  • setAutoCancel(): It sets the cancelable property of notification.
  • setPriority(): It sets the priority of notification.

Android Notification Example

In this example, we will create a notification message which will launch another activity after clicking on it.


Add the following code in an activity_main.xml file.

Create an activity named as activity_notification_view.xml and add the following code. This activity will be launched on clicking the notification. TextView is used to display the notification message.


In the class adds the following code. In this class, clicking the button calls the addNotification() method where we implement the NotificationCompat.Builder object to set the notification properties. The NotificationManager.notify() method is used to display the notification. The Intent class is used to call another activity ( on taping the notification.

The class receives the notification message and is displayed in TextView. This class is invoked while taping the notification.



Add the following code in AndroidManifest.xml file.


Android Notification Android Notification Android Notification Android Notification

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA