Building a Notification
Create and show a basic notification.
Building a Notification is a free Android Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Android Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Building a Notification
With a channel in place, you build the notification itself using NotificationCompat.Builder, then post it with the NotificationManager.
Why NotificationCompat
Always use NotificationCompat.Builder rather than the raw framework builder. It handles version differences for you, so one code path works across Android versions.
Creating the Builder
Pass the context and the channel id to the builder. The id must match a channel you already created.
val builder = NotificationCompat.Builder(context, Channels.MESSAGES)The Required Small Icon
setSmallIcon is mandatory. Without it, the notification will not display. Use a simple monochrome icon designed for the status bar.
val builder = NotificationCompat.Builder(context, Channels.MESSAGES)
.setSmallIcon(R.drawable.ic_notification)Title and Text
Set the headline with setContentTitle and the body with setContentText. These are the primary content the user reads.
.setContentTitle("New message")
.setContentText("Ada sent you a photo")Priority for Older Versions
On API 25 and below there are no channels, so importance comes from setPriority. Set it for backward compatibility; on API 26+ the channel importance wins.
.setPriority(NotificationCompat.PRIORITY_HIGH)Auto-Cancel on Tap
Call setAutoCancel(true) so the notification dismisses itself when the user taps it. Otherwise it lingers in the shade.
.setAutoCancel(true)Posting With notify
Build the notification and post it with notify, passing an integer id. The manager displays it in the status bar.
val notification = builder.build()
NotificationManagerCompat.from(context).notify(1001, notification)The Notification ID
The id you pass to notify identifies the notification. Posting again with the same id updates the existing one; a new id creates a separate notification.
Updating and Cancelling
To update, re-post with the same id and new content. To remove programmatically, call cancel(id) on the manager.
NotificationManagerCompat.from(context).cancel(1001)Expandable Styles
Use styles like BigTextStyle or BigPictureStyle to show more content when the user expands the notification.
.setStyle(
NotificationCompat.BigTextStyle()
.bigText("A long message that expands when tapped to reveal full content.")
)Quick Check
Test your understanding of building notifications.
Recap
You built and posted a notification:
- Use
NotificationCompat.Builder(context, channelId) setSmallIconis required; add title and text- Post with
notify(id, notification); same id updates, new id adds - Use styles and
setAutoCancelfor polish
Next: actions and deep links.
Frequently asked questions
Is the “Building a Notification” lesson free?
Yes — the full text of “Building a Notification” is free to read here on the web, and the Android Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Android Academy course, upgrade to CoddyKit PRO.
What will I learn in “Building a Notification”?
Create and show a basic notification. You practise Android Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Android Academy?
No prior experience is required. Android Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Building a Notification” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Android Academy lesson?
Yes. Every Android Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Notification Channels
- Building a Notification
- Actions and Deep Links
- The Notification Runtime Permission