Push Notifications That Open the Right Conversation

A persisted backend event connects a notification alert with a current record on another phone.
Concept illustration of notification delivery and fetching the current event record.

In the service apps I worked on, a notification could mean a new message, an available job, or an order update. Those events mattered, but the phone was not always ready to receive or display them. Permission, app state, device settings, and network conditions all shaped what happened next.

I built notification logic around chat and service events, including device-token records and scheduled delivery. One distinction runs through the implementation: the alert tells the user something happened, while the destination screen loads the current record.


Begin with a persisted event

A chat message or order transition should be recorded before notification delivery becomes part of the workflow. If a push is delayed or never shown, the underlying information still needs to exist.

For a new chat message, the backend determines the conversation’s authorized participants, excludes the sender where appropriate, and resolves the relevant device registrations. A conversation ID in the payload gives the client a destination; the backend then checks the user’s access.

This separation also makes notification failures easier to investigate. “Message saved” and “push request accepted” are different milestones, and neither proves that a person saw the alert.


Manage devices as part of the account lifecycle

One user can have several devices. One device can be used by several accounts over time. Token storage needs to reflect those relationships instead of keeping an unqualified token on a single user document.

Token refresh, logout, reinstall, and account switching all need consideration. An obsolete registration should not keep receiving another user’s events. Firebase’s registration-token guidance explains how to identify stale or invalid registrations. Cleanup must distinguish an invalid token from a malformed message or a temporary delivery failure.

Registration belongs behind an authenticated application endpoint, with the device identifier linked to the verified account. Use the registration and refresh APIs supported by the deployed SDK.


Handle each app state deliberately

Firebase’s Flutter receiving guide distinguishes foreground, background, and terminated behavior. It also documents permission requirements and notification-tap handling.

A typical Flutter integration includes these entry points:

// Illustrative wiring; handlers still need authorization and routing logic.
FirebaseMessaging.onMessage.listen(handleForegroundMessage);
FirebaseMessaging.onMessageOpenedApp.listen(handleNotificationTap);
final launchMessage = await FirebaseMessaging.instance.getInitialMessage();
if (launchMessage != null) queueNotificationRoute(launchMessage.data);

Opening a destination on a cold launch can require waiting for session restoration and navigation setup. I would queue the intent rather than immediately push a route from initialization code. The destination should then fetch current data and handle an order that is already complete or no longer available.

Background processing needs a separate handler where the platform requires it; it should not navigate the visible UI. Android notification channels control notification behavior, while iOS categories define notification types and actions. Each platform needs its own configuration and testing.


Avoid unnecessary or duplicate alerts

A notification about a conversation already on screen can be distracting. The foreground experience might update the message list without a second system alert. The decision depends on the event and user expectations.

Backend retries also create duplication risk. A useful design tracks the source event and intended recipient so repeated processing does not blindly create new scheduled alerts. Idempotency reduces avoidable duplicates in application processing. Delivery can still be repeated, delayed, or lost, so the destination must recover from those cases.

For a scheduled reminder, I would recheck relevance when the time arrives. An order may have changed or the user may have already responded. Sending the original reminder anyway is a product bug even if delivery succeeds.


Protect the lock-screen experience

Notification previews can expose message content or service details on a shared or locked device. I would favor minimal previews where the context is sensitive and let users control topics and presentation.

Localization matters here too. The alert should make sense in the user’s chosen language, and the linked screen should explain the same event consistently.


Verify the route end to end

The cases I would check include denied permission, foreground arrival, background tap, cold-launch tap, expired session, stale order, multiple devices, and logout followed by a new account.

My most useful notification tests start with the tap and follow it through session restoration, authorization, and the destination request. A correctly delivered alert can still open the wrong account or a stale order. Those are application failures worth checking directly.