Android
Push Notifications
Mobile Development
Android Notifications
App Development

Push Notifications in Android Platform

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

On Android, push notifications are usually delivered through Firebase Cloud Messaging, or FCM. The complete flow has three parts: the device registers for a token, your backend sends a message to FCM, and the app receives that message and turns it into a user-visible notification.

Core pieces of the Android push stack

An Android push setup normally includes:

  • Firebase in the Android app,
  • an FCM registration token for the device or app instance,
  • a backend or Firebase console message sender,
  • and Android notification channels for user-visible delivery.

FCM handles the transport, while your app decides how to display the message once it arrives.

Add Firebase Messaging and declare the service

At the app level, add the messaging dependency:

kotlin
dependencies {
    implementation("com.google.firebase:firebase-messaging:24.1.0")
}

Then implement a FirebaseMessagingService:

kotlin
1class MyFirebaseMessagingService : FirebaseMessagingService() {
2
3    override fun onNewToken(token: String) {
4        Log.d("FCM", "Token: $token")
5        // Send the token to your backend if you target this device directly.
6    }
7
8    override fun onMessageReceived(message: RemoteMessage) {
9        val title = message.notification?.title ?: "Update"
10        val body = message.notification?.body ?: "You have a new message."
11        showNotification(title, body)
12    }
13}

And register it in AndroidManifest.xml:

xml
1<service
2    android:name=".MyFirebaseMessagingService"
3    android:exported="false">
4    <intent-filter>
5        <action android:name="com.google.firebase.MESSAGING_EVENT" />
6    </intent-filter>
7</service>

Build a notification channel and post the notification

On Android 8.0 and higher, notifications need a channel:

kotlin
1private fun Context.ensureGeneralChannel() {
2    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
3        val channel = NotificationChannel(
4            "general",
5            "General updates",
6            NotificationManager.IMPORTANCE_DEFAULT
7        )
8
9        val manager = getSystemService(NotificationManager::class.java)
10        manager.createNotificationChannel(channel)
11    }
12}

And the actual notification can be built with NotificationCompat:

kotlin
1private fun FirebaseMessagingService.showNotification(title: String, body: String) {
2    applicationContext.ensureGeneralChannel()
3
4    val notification = NotificationCompat.Builder(this, "general")
5        .setSmallIcon(R.drawable.ic_notification)
6        .setContentTitle(title)
7        .setContentText(body)
8        .setAutoCancel(true)
9        .build()
10
11    NotificationManagerCompat.from(this).notify(1001, notification)
12}

Android 13 and newer require notification permission

Starting with Android 13, most apps must request the POST_NOTIFICATIONS runtime permission before posting non-exempt notifications. That means a modern Android notification flow needs both the manifest entry and a runtime permission request.

xml
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

At runtime, request it from an activity when appropriate to your UX:

kotlin
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), 100)
}

Without that permission, the app may receive an FCM message but fail to show a visible notification.

Sending messages and handling payloads

FCM supports two common message styles:

  • notification messages, which focus on user-visible title and body content,
  • data messages, which give your app structured custom fields to handle itself.

Data messages are often better when the app needs to decide exactly how navigation, caching, or in-app state updates should work.

Common Pitfalls

The biggest mistake is treating FCM setup as complete after the dependency is added. The app still needs a registered messaging service, a notification channel, and permission handling on recent Android versions.

Another common issue is ignoring token lifecycle. FCM tokens can change, so if your backend targets individual devices, it must accept token updates from onNewToken.

Be careful with notification payloads in the background. Depending on the message type and app state, the system may display parts of the message automatically while your data-handling code runs differently than expected.

Finally, notifications are a product surface, not just a transport feature. Bad channel naming, noisy defaults, or permission prompts shown too early can hurt user trust even when the code is technically correct.

Summary

  • Android push notifications are typically built on Firebase Cloud Messaging.
  • The app needs Firebase Messaging, a FirebaseMessagingService, and notification-channel setup.
  • Android 13 and higher generally require the POST_NOTIFICATIONS runtime permission.
  • FCM token management matters if your backend targets specific devices.
  • A reliable push system depends on both transport setup and good notification UX.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.