Notifications and channels

Background work and notifications Junior Kotlin 2.0+ API 26+ Reviewed By Best Latest Apps

Order the steps

Order the steps to post an order-update notification.

  • Create the 'Order updates' channel once
  • Build the notification with an immutable content PendingIntent
  • Post with NotificationManagerCompat.notify
  • Ask for POST_NOTIFICATIONS when the user opts into updates

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A D B C

  1. Create the 'Order updates' channel once Channels must exist before posting on Android 8+.
  2. Ask for POST_NOTIFICATIONS when the user opts into updates Required on Android 13+.
  3. Build the notification with an immutable content PendingIntent The tap opens the order.
  4. Post with NotificationManagerCompat.notify Shows it if permission and channel allow.

30-second answer

Create a NotificationChannel (Android 8+) with an importance level once, usually at startup, then build notifications with NotificationCompat.Builder on that channel. On Android 13+ you also need the POST_NOTIFICATIONS runtime permission. Use a content intent with an immutable PendingIntent, and pick channels by purpose so users can turn off marketing without losing order updates.

Practise saying it · 35 s. No recording, just a timer

Explain what a notification needs today.

Say your answer out loud, then check which of these points you covered:

  • Channels by purpose
  • POST_NOTIFICATIONS on 13+
  • Immutable PendingIntent
  • Users control channels

Deep dive

Users control channels after creation; you can't raise a channel's importance later.

Group related notifications with setGroup and a summary.

Use MessagingStyle for chats, which enables bubbles and better wear display.

Full-screen intents are restricted to calls and alarms since Android 14.

A channel and a notification Compile-checked · Kotlin 2.4.21
fun notifyOrder(context: Context, orderId: Int, tap: PendingIntent) {
    val manager = NotificationManagerCompat.from(context)
    manager.createNotificationChannel(
        NotificationChannelCompat.Builder("orders", NotificationManagerCompat.IMPORTANCE_DEFAULT)
            .setName("Order updates").build()
    )
    val n = NotificationCompat.Builder(context, "orders")
        .setSmallIcon(android.R.drawable.stat_notify_more)
        .setContentTitle("Your order shipped")
        .setContentIntent(tap)
        .setAutoCancel(true)
        .build()
    if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) {
        manager.notify(orderId, n)
    }
}

Common mistakes

  • One channel for everything.
  • Posting before the permission is granted on Android 13+ and assuming it showed.
  • Changing a channel's importance in code and expecting it to apply.

Senior take & follow-ups

Mention channel design by purpose and the Android 13 permission.

Follow-up questions

Think of your answer first, then open the hint.

  1. Can you change a channel's importance?

    Show hint

    Only the user can after it's created; you'd need a new channel ID.

  2. What's required on Android 13?

    Show hint

    The POST_NOTIFICATIONS runtime permission.

Similar on iOS: How push notifications are delivered iOS has no channels; users toggle notifications per app and by category.

Suggest a fix if something here is wrong or out of date.