startForeground not called 🤖 Android

Context.startForegroundService() did not then call Service.startForeground() / ForegroundServiceStartNotAllowedException

A foreground service didn’t call startForeground() within a few seconds, or the app tried to start one from the background where Android 12+ forbids it.

Seen on: Android

Meaning

Android 14 also requires a foregroundServiceType declared in the manifest plus the matching FOREGROUND_SERVICE_* permission. Background starts should use WorkManager (expedited work) instead.

Common causes

  • startForeground() not called quickly in onStartCommand
  • Started from background (Android 12+ restrictions)
  • Missing foregroundServiceType/permission (Android 14)
  • Notification channel missing

⚡ Quick fix

  1. Call startForeground() immediately with a notification
  2. Declare android:foregroundServiceType and the permission
  3. Use WorkManager for background-initiated work

Detailed fix by platform

XML

  1. kotlin
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
    <service android:name=".SyncService" android:foregroundServiceType="dataSync" android:exported="false" />

How to diagnose

  1. Timing — startForeground called within 5–10 s?
  2. Start — From foreground or background?
  3. Manifest — Type and permission

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.