Actions and Deep Links
Add buttons and open the right screen.
Actions and Deep Links is a free Android Academy lesson on CoddyKit — lesson 3 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.
Actions and Deep Links
Notifications become useful when they do something. Tapping one should open the right screen, and action buttons should perform quick tasks. Both rely on PendingIntent.
What a PendingIntent Is
A PendingIntent is a token you hand to the system that lets it execute an Intent on your behalf later, even when your app is not running. Notifications use it to launch your activity.
Creating a Content PendingIntent
Build an Intent for the screen to open, wrap it in a PendingIntent, and attach it with setContentIntent so a tap opens that screen.
val intent = Intent(context, MainActivity::class.java)
val pending = PendingIntent.getActivity(
context, 0, intent,
PendingIntent.FLAG_IMMUTABLE
)
builder.setContentIntent(pending).setAutoCancel(true)The Mutability Flag
Since Android 12, a PendingIntent must specify FLAG_IMMUTABLE or FLAG_MUTABLE. Prefer FLAG_IMMUTABLE unless the system needs to fill in data (as with some replies).
Adding an Action Button
Use addAction with an icon, a label, and a PendingIntent to add a tappable button to the notification, such as "Reply" or "Mark as read".
builder.addAction(
R.drawable.ic_reply,
"Reply",
replyPendingIntent
)Actions Trigger Components
An action's PendingIntent can target an Activity, a Service, or a BroadcastReceiver. A "Mark as read" button often targets a receiver so it works without opening any screen.
val markIntent = Intent(context, MarkReadReceiver::class.java)
val markPending = PendingIntent.getBroadcast(
context, 0, markIntent, PendingIntent.FLAG_IMMUTABLE
)Deep Linking to a Screen
A deep link opens a specific destination inside your app, not just the home screen. With Navigation Compose you can build a PendingIntent that lands on an exact route.
Building a Deep Link PendingIntent
The Navigation component offers NavDeepLinkBuilder (or a deep-link Intent with a URI) to construct a PendingIntent targeting a destination and arguments.
val deepLinkPending = NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.chatScreen)
.setArguments(bundleOf("chatId" to "42"))
.createPendingIntent()URI-Based Deep Links
You can also register a URI pattern in your nav graph and create an Intent with that Uri. Tapping the notification then routes straight to the matching screen.
val intent = Intent(
Intent.ACTION_VIEW,
"myapp://chat/42".toUri(),
context, MainActivity::class.java
)Preserving Back Stack
For deep links, ensure a sensible back stack so pressing Back returns to a parent screen rather than exiting the app. TaskStackBuilder or the nav deep-link builder handles this.
Unique Request Codes
If you create multiple PendingIntents that differ, give each a distinct request code (the second argument). Identical intents with the same code are treated as the same PendingIntent.
Quick Check
Test your understanding of actions and deep links.
Recap
You added interactivity:
PendingIntentlets the system act on your behalf; useFLAG_IMMUTABLEsetContentIntentdefines the tap actionaddActionadds buttons targeting activities, services, or receivers- Deep links open exact screens with a preserved back stack
Next: the notification runtime permission.
Frequently asked questions
Is the “Actions and Deep Links” lesson free?
Yes — the full text of “Actions and Deep Links” 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 “Actions and Deep Links”?
Add buttons and open the right screen. 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 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Actions and Deep Links” 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