How does push notification technology work on Android?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Push notifications are a critical part of modern mobile applications, enabling seamless communication between the app and users. Android uses Google Cloud Messaging (GCM) and more recently, Firebase Cloud Messaging (FCM) to deliver push notifications. This article delves into the technology behind push notifications on Android, offering insights into how they work, the architecture involved, and practical examples.
The Architecture of Push Notifications
Push notifications on Android primarily work using an architecture that involves three key components:
- Client App: The mobile application that receives notifications.
- Google (or Firebase) Cloud Messaging Service: The intermediary service that handles the sending and immediate delivery of notifications.
- App Server: The third-party server which initiates the push notification request.
Here's how each part interacts to send a push notification:
- Client App Registration: The app registers with the FCM server upon installation to receive notifications. FCM assigns a unique token to the app that identifies it on the network.
- Token Storage: This token is sent back to the app server, where it is stored for future notification dispatches.
- Sending Notifications: When the app server decides to send a notification, it does so by creating a push notification message and sending it to FCM along with the recipient's token.
- FCM Processing: FCM processes this message and identifies the target app using the provided token.
- Notification Delivery: FCM delivers the message to the user's device, and the Android system then conveys it to the app through the notification bar.
Detailed Workflow
- Application Registration: When a user installs or opens an app for the first time, the app initiates a registration process with FCM. This is done using a method such as:
- E-commerce Apps: Notifying users about sales, discounts, and order statuses.
- Social Media Apps: Informing users about new messages, likes, or friend requests.
- News & Media Apps: Alerting users about breaking news and important articles.
- Authentication: Only authenticated services can send notifications. This is managed via API keys and OAuth 2.0 tokens.
- Encryption: Payload data can be end-to-end encrypted to maintain user privacy.
- Batching Messages: Deliver multiple notifications together instead of one at a time.
- Priority Settings: Use priority settings to dictate the urgency of messages, reducing unnecessary wake locks on the device.
Related reading
- How does setting baselineAligned to false improve performance in LinearLayout?
- How does String substring work in Swift
- How does String.Index work in Swift
- How does TestFlight do it?
- How does View Controller Containment work in iOS 5?
- How exactly does the androidonClick XML attribute differ from setOnClickListener?
- How is Swift if let evaluated?
- How ListView's recycling mechanism works
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.