NotificationServiceExtension. The pattern mirrors iOS Live Activities, but it is implemented in your app code rather than provided by OneSignal as a managed feature. Use it for progress bars, sports scores, ride status, or any other content that should update inside one persistent notification instead of stacking new pushes.
Live Notifications require the user to have push notifications enabled.
Requirements
- Latest OneSignal Android SDK integrated in your app.
- The end user has granted push notification permission.
- A
NotificationServiceExtensionin your app to intercept and render Live Notifications. See Service extensions for background.
How it works
OneSignal is the transport. Your app code defines the schema and renders the UI. The flow:- Your backend calls the Create message API with a
collapse_idand a structuredlive_notificationobject insidedata. - OneSignal delivers the push to the device.
- Your
NotificationServiceExtensionintercepts every push, looks for thelive_notificationkey, and dispatches based on itsevent(start,update, orend). - Your code calls
NotificationManager.notify(id, …)with the same Android notification ID each time, which updates the existing notification rather than posting a new one.
The
live_notification payload, its field names, and the start / update / end event values are a convention introduced by this guide. They are not enforced by OneSignal. You can rename or restructure anything as long as your service extension and your sending backend agree.Live Notifications vs. standard push
Unlike regular push notifications, which post a new notification each time, Live Notifications use one persistent notification updated over time. Two things make this work:collapse_idon the API side keeps later messages tied to the same logical notification. See Collapse ID (mobile push).- A stable Android notification ID on the device side lets
NotificationManager.notify(id, …)replace the visible notification’s contents instead of stacking a new one.
Implementation
1. Add a Notification Service Extension
Create a class that implementsINotificationServiceExtension. The class below is complete and runnable: it creates the notification channel on first use, parses the live_notification payload, dispatches by event, and renders a progress notification as an example.
NotificationServiceExtension.kt
The
@Keep annotation prevents R8 or ProGuard from stripping or renaming this class when minification is enabled. See Service extensions for more on writing service extensions.2. Register the extension in the Android Manifest
Add thecom.onesignal.NotificationServiceExtension meta-data tag inside <application>, pointing to the fully qualified name of your class.
3. Define your Live Notification payload
Each Live Notification carries alive_notification object inside the push’s data field. The schema is a convention you control. The shape used in this guide:
| Property | Required | Description |
|---|---|---|
key | Yes | Identifies which Live Notification UI to render and which Android notification ID to reuse. |
event | Yes | Lifecycle event: start, update, or end. |
event_attributes | No | Static data passed once on start. Use it for fields that don’t change for the life of the notification (team names, order ID, etc.). |
event_updates | No | Dynamic data passed on start and every update. The shape is whatever your builder consumes (scores, percentages, ETAs). |
4. Handle the lifecycle events
Your service extension dispatches on theevent field. The example code above does this in handleLiveNotification.
| Event | Description | Required fields |
|---|---|---|
start | Creates the Live Notification with static and dynamic data. | event_attributes, event_updates |
update | Updates the existing Live Notification with new dynamic data. | event_updates |
end | Removes the Live Notification by calling NotificationManager.cancel(id). | None |
Send a Live Notification
Sendstart, update, and end events with the Create message API. Every request must:
- Set the same
collapse_idso OneSignal collapses later messages onto the first one. The ID must be unique to that specific Live Notification instance. - Target the same set of users (typically with
include_aliases.external_id). - Use
isAndroid: trueto restrict delivery to Android push subscriptions.
Start
Sendevent: "start" to create the Live Notification. Initialize both static (event_attributes) and dynamic (event_updates) data.
Start
Update
Sendevent: "update" with new event_updates data. You can update as many times as you like after start.
Update
End
Sendevent: "end" to dismiss the Live Notification. The service extension calls NotificationManager.cancel(id) to remove it from the user’s device.
End
FAQ
Are Android Live Notifications a managed OneSignal feature?
No. They are a pattern you implement in yourNotificationServiceExtension on top of OneSignal push and Android’s NotificationManager. OneSignal does not track Live Notification state, manage update lifecycles, or expose Live Notifications in the dashboard. The schema and event names in this guide are conventions you can change.
Why do I need both collapse_id and a stable Android notification ID?
They solve different problems. collapse_id deduplicates messages on the OneSignal side and APNs/FCM side so the device only processes the latest one if updates arrive in a burst. The stable Android notification ID is what NotificationManager.notify(id, …) uses to replace the visible notification’s contents instead of posting a new one. You need both.
How often can I send updates?
Frequent updates are fine, but use a low importance channel (IMPORTANCE_LOW) with badges, vibration, and sound disabled. High importance with frequent updates will alert the user every time and is the most common reason support tickets get opened for this pattern.
What happens if the user kills the app or device reboots?
The Android notification persists on the lock screen and notification shade until your app cancels it or the user dismisses it. The service extension only runs when a push arrives, so any in-memory state (like progress) must be encoded inevent_updates, not held in app memory.
Can I do this on iOS too?
iOS has a managed equivalent: Live Activities. It uses ActivityKit and is built into OneSignal as a first-class feature with its own Start and Update APIs. Use Live Activities on iOS rather than this pattern.Related pages
Service extensions
Intercept and customize push notifications before display on Android and iOS.
Create message API
The API used to send the start, update, and end pushes for a Live Notification.
Live Activities (iOS)
The managed iOS equivalent built on ActivityKit.
Android notification categories
Configure channels so frequent Live Notification updates don’t alert the user.