Skip to main content
Keep calls alive when users navigate away from your app. Background handling ensures the call continues running when users press the home button, switch to another app, or lock their device.

Overview

When a user leaves your call screen, the operating system may terminate it to free resources. The SDK provides CometChatOngoingCallService — a utility that:
  • Keeps the call session active in the background
  • Shows an ongoing notification in the status bar (Android)
  • Allows users to return to the call with a single tap
  • Provides a hangup action directly from the notification

When to Use

Background Handling is different from Push Ringing. They cover different phases of a call on Android:cometchat_voip stops its service once the session is joined, so a joined call needs this page whether it was rung through push or not. It applies to every call: ringing calls, direct calls, group calls and meetings.
Using the CometChat UI Kit? Its call screen starts CometChatOngoingCallService when the call joins and stops it when the call ends. You only need to declare the service, as in Step 1.
CometChatOngoingCallService starts an Android foreground service with a persistent notification showing mute/unmute and hang up actions. On iOS, this is a no-op since iOS uses CallKit for ongoing call notifications.

Implementation

Step 1: Declare the service and permissions (Android)

Add the ongoing call service and the notification permission to android/app/src/main/AndroidManifest.xml:
The Calls SDK declares the foreground service permissions the service needs (FOREGROUND_SERVICE, FOREGROUND_SERVICE_MICROPHONE and FOREGROUND_SERVICE_CAMERA). On Android 13 and later, request POST_NOTIFICATIONS at runtime as well (cometchat_voip already declares and requests it if your app uses it).
The <service> element is not optional. OngoingCallService lives in the SDK, but an Android app must declare every service it starts in its own manifest. Without it the call keeps running while your app is open, but no ongoing notification appears and the call can be stopped as soon as the user leaves the app. The SDK logs a warning when the service is not declared.

Optional: keep the notification when the microphone is denied

If a user joins a call without granting the microphone, the call continues listen-only. To keep the ongoing notification and the background protection in that case, add the mediaPlayback type and its permission:
Google Play asks you to justify each foreground service type your app declares. Declare mediaPlayback only if you can justify it for your app.

Step 2: Start the service on join, stop it on leave

Start the ongoing call service when the user joins the call session, and stop it when the call ends. Pass isVideo: false for an audio call, so the service doesn’t use the camera.
The service and its notification stay for the whole call, whether your app is in the foreground or not, until you call abort().
Flutter listeners are not lifecycle-aware. You must manually remove listeners in dispose() and call CometChatOngoingCallService.abort() to clean up.

API Reference

CometChatOngoingCallService

On iOS, ongoing call state is managed by CallKit automatically. CometChatOngoingCallService.launch() and abort() are safe to call on iOS — they simply do nothing.

  • Picture-in-Picture - Keep call visible while using other apps
  • Push Ringing - Ring calls when the app is in the background or killed, until the answered call joins
  • Events - Listen for session events