Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Android foreground notification error - $ForegroundServiceDidNotStartInTimeException #1242

@ryelibra37

Description

@ryelibra37

Really useful package 🙌

1. Summary

In firebase there are many crashes from my foreground notification in android:

Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{72fd4ec u0 XXXXXXXXXXXX/app.notifee.core.ForegroundService c:XXXXXXXXXX}

2. Environment

  • @notifee/react-native version: 9.1.8
  • react-native info:
    System:
      OS: macOS 15.1
      CPU: (10) arm64 Apple M4
      Memory: 108.92 MB / 16.00 GB
      Shell:
        version: "5.9"
        path: /bin/zsh
    Binaries:
      Node:
        version: 22.13.0
        path: ~/.nvm/versions/node/v22.13.0/bin/node
      Yarn:
        version: 1.22.22
        path: ~/.nvm/versions/node/v22.13.0/bin/yarn
      npm:
        version: 10.9.2
        path: ~/.nvm/versions/node/v22.13.0/bin/npm
      Watchman:
        version: 2024.12.02.00
        path: /opt/homebrew/bin/watchman
    Managers:
      CocoaPods:
        version: 1.16.2
        path: /Users/xxxxx/.rbenv/shims/pod
    SDKs:
      iOS SDK:
        Platforms:
          - DriverKit 24.2
          - iOS 18.2
          - macOS 15.2
          - tvOS 18.2
          - visionOS 2.2
          - watchOS 11.2
      Android SDK: Not Found
    IDEs:
      Android Studio: 2024.2 AI-242.23726.103.2422.12816248
      Xcode:
        version: 16.2/16C5032a
        path: /usr/bin/xcodebuild
    Languages:
      Java:
        version: 17.0.2
        path: /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home/bin/javac
      Ruby:
        version: 3.4.1
        path: /Users/xxxxxx/.rbenv/shims/ruby
    npmPackages:
      "@react-native-community/cli":
        installed: 15.0.1
        wanted: 15.0.1
      react:
        installed: 18.3.1
        wanted: 18.3.1
      react-native:
        installed: 0.76.9
        wanted: 0.76.9
      react-native-macos: Not Found
    npmGlobalPackages:
      "*react-native*": Not Found
    Android:
      hermesEnabled: true
      newArchEnabled: true
    iOS:
      hermesEnabled: true
      newArchEnabled: true
    

3. Platform & Device Details

  • Platform: Android
  • Affected Android Versions: android 12+
  • Devices: All devices and emulators

4. Problem Description & Proposed Solution

I am using the notifee displayNotification method to display a foregroundService notification on android like this:

notifee.displayNotification({
    id: 'timer_foregroung_service_notification',
    title,
    subtitle,
    body,
    android: {
      channelId: TIMER_CHANNEL_ID,
      asForegroundService: true,
      color: color as AndroidColor,
      colorized: true,
      smallIcon: 'ic_notification_pic',
      pressAction: {
        id: 'default',
        launchActivity: 'default',
      },
      onlyAlertOnce: true,
    }
  });

I noticed that when I call this method for the first time after the app has been inactive is takes about 10 seconds before the first foreground service notification shows up. But once the foreground service notification is active the subsequent notifications pull through straight away. If I exit the screen, and come immediately back in the foreground service notifications work correctly straight away. It seems there is a delay when starting after a long time inactive (above 2 mins).

After some searching, there are a few people online with similar issues, and the delay is potentially cause by android itself:

https://stackoverflow.com/questions/73074639/android-foreground-service-notification-delayed

mauron85/react-native-background-geolocation#560

It seems to get the foreground service to start immediately we need to pass FOREGROUND_SERVICE_IMMEDIATE into setForegroundServiceBehavior().

// Native Android code
builder.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE);

I wanted to patch the package but I couldn't find anywhere in the codebase to attach this setForegroundServiceBehavior. Could the package expose this as an option, or could you point me in direction of how I can patch the package to show this option?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions