How to refresh push notification subscription for azure chat when app is Terminated

yrmal 20 Reputation points
2025-05-23T06:58:07.7266667+00:00

Hello,

I’ve implemented chat push notifications for Azure Communication Services Chat following this documentation: https://learn.microsoft.com/en-us/azure/communication-services/tutorials/add-chat-push-notifications#download-code

As noted, the push notification subscription must be refreshed every 45 minutes. The documentation provides guidance on how to handle this while the app is running in the background.

However, I’d like clarification on how to handle subscription renewal when the app is terminated (either by the system or the user force quitting the app). In this state, background tasks are not running, so what is the recommended approach to ensure the push notification subscription remains valid?

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
1,233 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bhargavi Naragani 5,270 Reputation points Microsoft External Staff Moderator
    2025-05-23T08:25:57.56+00:00

    Hi @yrmal,

    When the app is terminated:

    • The OS (iOS/Android) does not allow background code execution.
    • Timers and background services are stopped, so you cannot automatically refresh the push notification subscription.
    • This means your app will stop receiving ACS chat push notifications once the 45-minute subscription window expires, unless the user manually reopens the app.

    To ensure the push notification subscription remains valid after the app is terminated, consider the following approach:

    1. When you create or renew the subscription, save the timestamp of the renewal in local storage (like SharedPreferences on Android or UserDefaults on iOS). Also, store the token or registration state if needed for comparison later.
    2. When the app starts up (after being terminated), immediately check if the subscription is expired or close to expiring (e.g., more than 40 minutes old). If it is, renew the push notification subscription right away to resume receiving messages.
    3. Unfortunately, messages sent during the window when the app was terminated, and the subscription expired will not be delivered. However, once the user opens the app again, you can resubscribe and start receiving new notifications as normal.
    4. Unfortunately, there is no way to automatically renew the subscription while the app is terminated, because push subscription management requires the app to execute code, and iOS/Android do not allow this from a terminated state.

    https://learn.microsoft.com/en-us/azure/communication-services/concepts/notifications
    https://learn.microsoft.com/en-us/azure/communication-services/concepts/chat/concepts
    https://developer.android.com/guide/components/activities/activity-lifecycle
    https://developer.apple.com/documentation/uikit/managing-your-app-s-life-cycle

    Hope the above provided information was helpful, if you have any further concerns or queries, please feel free to reach out to us.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.