Udemy logo

android notification settingsAndroid is the most popular mobile platform in the world today. According to the latest data, more than a million applications have been created for the operating system, with about 25 billion downloads to date. The number of people using Android based smartphones is also growing steadily. Because of this, there is a large demand in the market for Android apps of all kinds, from utility apps to games. This is the best time to learn how to become an Android developer. This Android 101 course is a good place to start.

In this tutorial, we’re going to take a look at how to design and create basic notifications, and the different settings you should use for them. You need to be familiar with the basics of Java to understand this tutorial. If you’re new to it, you may want to first take this basic course for Android.

Android Notifications

Notifications are a great way to keep a user updated with an app’s activity, like a calendar event or an incoming message from a friend. They also help ensure that the user keeps coming back to your app and doesn’t forget about it, whatever your app is.

The notification system in Android is flexible and well designed. You can customize the notifications your app sends out to your user by using the NotificationCompat.Builder object. A typical notification consists of the following things:

Some of the components of a notification are optional. For a list of what you can skip, check out the official documentation here.

Creating a Simple Notification Object

As we mentioned before, you can create a notification by using the NotificationCompat.Builder object. You call the NotificationCompat.Builder.build () method, which will return a Notification object that contains your data. You need to call NotificationManager.notify () to pass the Notification object to the system.

The notification object you are about to define should contain the following things a small icon, tile as well as some textual content. The small icon is set by the setSmallIcon () method, the title is set by the setContenttitle() and the Detail text by the setContentText ().

It’s recommended that you add actions to your notifications, although it’s not mandatory. An Activity (event) is started when a user clicks on the notification, through an action button. This Activity will contain he details of what your application is supposed to do when the user clicks on it.

We’ll show you how to create a simple notification object with the help of some code in the official Android developer application:

NotificationCompat.BuildermBuilder =
 new NotificationCompat.Builder(this)
.setContentTitle("My notification")
.setContentText("Hello World!");
 Intent resultIntent = new Intent(this, ResultActivity.class);
 TaskStackBuilderstackBuilder = TaskStackBuilder.create(this);
 PendingIntentresultPendingIntent =
 NotificationManagermNotificationManager =
 (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 mNotificationManager.notify(mId, mBuilder.build());

In this example, they’ve created a notification opens when the user clicks on it and allows an activity to be selected. The first part of the program deals with declaring a new object and creating an icon, a title and a message contained in the notification. Declaring an Intent will result in an Activity happening in the program. If the user declines to perform an Activity and backtrack, he will end up on the home screen of the device. This program uses several advanced Java techniques. To learn more about them, we recommend you sign up for our Android development course.

Notification Settings

When you think about notification settings for your Android application, there are several things to consider. It’s a good idea to study the notification system on a few popular applications before creating settings for your own.

The notifications that your application displays should always be controllable by the user. There should also be an option to turn off notifications entirely. A user should get the option to choose how the notification sent out by your application should appear on screen, like with a beeping sound or by activating the user’s ringtone.

Also, you should consider if you want your application to show messages with low priority or just high priority. In Jelly Bean and newer versions of Android, your applications have the ability to display high priority and low priority notifications. Notifications with the highest priority, highlighted by a priority flag, always appear at the top of the heap:

When creating notifications, try to make that your app sends out important notifications only.  To learn how to design the layout of your notifications and how to add activities to them, you can take this UI design course.  If you’d like help starting off with your Android app design, this course can help you. And while you’re at it, don’t forget to have fun!

Page Last Updated: May 2014

Android Development students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.

Request a demo