Push Notification in Android. How does it Work?

Kaushal Vasava
4 min readNov 7, 2023

--

I’ll show you what is push notification and how it works under hood?

Android Push Notifications: What Are They?

The mobile operating system Android manages push notifications from different applications. These notifications appear in the notification center and prompt the user to take a specific action. Android notifications generally have a thumbnail image, a title, some text and one or more prompts to elicit user actions. Each notification can have its own alert style, sound, and vibration styles. Users can configure their preferences in their notification center settings.

There are two primary types of Android push notifications:

  • Default: These are the simplest types of Android push notifications. Such notifications can have a thumbnail and some text. Clicking on the notification will directly launch the relevant page of the Android application.
  • Interactive: Interactive notifications have buttons within the notification, which users can interact with without launching the Android application. For example, the music player will have a notification with play/pause, next, and previous buttons. Users can interact with those buttons to perform certain actions without launching the music player.

Depending on the content in the notifications, Android push notifications can also be classified into utility notifications, update notifications, and promotional notifications. Depending on the category, the Android operating system has the power to limit the reach of your notifications.

Push notifications, in particular, are an effective means to engage users and boost user retention.

How Does an Android Push Notification Work?

Android keeps one active connection to Google’s servers, but it doesn’t use much power or data, because no traffic is sent along it until something sends a Google Cloud Messaging (GCM) message to an app on your phone. There’s only one connection on the phone, used by all apps: installing a new app that uses GCM doesn’t add any extra load.

The first step in GCM is that a third-party server (such as an email server) sends a request to Google’s GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it’s for, and starts that app. The app must have registered with Android to use GCM, and it must have the relevant permission. When the app starts, it might create a notification straight away with the data from the message. GCM messages are very limited in size, so the app might instead open a normal connection to the third-party server to get more information (for example, downloading the headers of new emails).

In order to send push notifications to an Android user, they must have your Android application installed. The user also has to opt-in to receive push notifications from your applications. Once these two fundamental requirements are in place, you will be able to send push notifications to Android users.

Three components have to be in place to send push notifications to Android users:

  • Client application: The client application is your Android application that the user has installed on their Android smartphone. The user should also have opted-in to receive push notifications. Only then will you be able to send push notifications to the user.
  • Server application: The server application refers to the place where the logic of your notifications resides. Some push notifications are generated by the client application, while others are pushed from a remote server to the client application. The code logic that pushes notifications is termed a server application.
  • Firebase Cloud Messaging: An operating system push notification service (OSPNS) is required to forward the push notification from the server application to the client application. Firebase Cloud Messaging (FCM) is the OSPNS for Android push notifications.

The advantage of using push notifications is that apps don’t have to run at regular intervals to check for new data, saving both power and data. The advantage of having a centralized mechanism like GCM is that the device only needs one open network connection and the Android GCM system is the only thing that needs to keep running, rather than each app having to stay running in the background to keep its own network connection to its own server.

When users opt-in for push notifications from your Android application, a device token is generated. This is used to identify users in the application. When you want to push a new notification, you have to pass the content and device token to FCM. FCM connects the right client application and push out the notification. You can also use an SDK to automate many elements of creating and tracking push notifications.

Resources

Learn how to implement it.

Thank you for reading. 🙌🙏✌.

Don’t forget to clap 👏 and follow me for more such useful articles about Android Development, Kotlin & KMP.

If you need any help related to Android, Kotlin and KMP. I’m always happy to help you.

Follow me on:

Medium, LinkedIn, Twitter, GitHub, and Instagram.

--

--

Kaushal Vasava

Android Developer | Kotlin | Jetpack Compose | Kotlin MultiPlatform | LinkedIn's Top Voice (3K+ Followers) | Apps with 100K+ Downloads on the Playstore