Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Flutter and app store releases · Decision guide

A foreground service that worked before crashes on Android 14 and later

Short answer

From targetSdk 34, a foreground service crashes unless the manifest gives it an android:foregroundServiceType, the app declares the matching FOREGROUND_SERVICE_<TYPE> permission, and the type's runtime rules hold. Read the exception in logcat: MissingForegroundServiceTypeException means no type, SecurityException means a missing permission or a start from the background. Applies to Android 14, 15 and 16.

  • Applies to Android 14, 15 and 16 (targetSdk 34 to 36), androidx.core ServiceCompat 1.12 or later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

On Android 14 (targetSdk 34) and later, a foreground service needs three things: a foregroundServiceType in the manifest, the matching FOREGROUND_SERVICE_<TYPE> permission, and, for some types, the runtime rules of the sensor behind it. Miss one and the app crashes at startForeground(). Older targets got away with all three, which is why the crash often appears right after raising targetSdk, something Google Play requires for updates.

The exception class is the fastest guide. Reproduce the crash and read it with adb logcat -b crash -d, then pick the row below.

Find your case

  1. If MissingForegroundServiceTypeException: Starting FGS without a typeThe service has no type in the manifest.
  2. If SecurityException naming an android.permission.FOREGROUND_SERVICE_ permissionThe type is declared but its permission is not.
  3. If SecurityException also listing ACCESS_FINE_LOCATION, CAMERA or RECORD_AUDIOA sensor type needs its runtime permission and a visible app.
  4. If ForegroundServiceStartNotAllowedException with mAllowStartForeground falseThe app started the service from the background.

Add the type to the manifest

Android throws MissingForegroundServiceTypeException when an app targeting Android 14 calls startForeground() for a service whose manifest entry has no type. Check your own manifest, and then the Merged Manifest view in Android Studio, because a library can add a service you never wrote.

Find services without a type

grep -n -A4 "<service" app/src/main/AndroidManifest.xml

Declare it and pass it when starting

Pick the type that matches what the service really does, such as dataSync, location, mediaPlayback or connectedDevice. Pass the same type when you start it, using ServiceCompat from androidx.core 1.12 or later.

<service
    android:name=".SyncService"
    android:foregroundServiceType="dataSync"
    android:exported="false" />

// in the service, Kotlin
ServiceCompat.startForeground(
    this, NOTIFICATION_ID, notification,
    ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
)

Declare the matching permission

Each type has its own normal permission, such as FOREGROUND_SERVICE_DATA_SYNC or FOREGROUND_SERVICE_LOCATION, on top of the general FOREGROUND_SERVICE permission. Without it the SecurityException is raised as soon as startForeground() runs. Both are install-time permissions, so no runtime prompt is needed for these two.

Next to the application element

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

After a clean reinstall the service should run, and adb logcat -d | grep "Starting FGS with type" should print nothing.

Location, camera and microphone services

These types also need the user-granted permission behind them. They count as while-in-use permissions, so the service must start while an activity is visible. Android 14 throws the moment such a service is created from the background, where earlier versions let it start and failed only when it touched the sensor.

checkSelfPermission still reports granted while the app is in the background, so it does not prove the screen is visible. Tie the start to a user action on that screen.

Ask first, start from the visible screen

if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
        == PackageManager.PERMISSION_GRANTED) {
    ContextCompat.startForegroundService(this, Intent(this, TrackingService::class.java))
} else {
    requestPermissions(arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), REQUEST_LOCATION)
}

Starting from the background

Since Android 12, apps targeting API 31 or higher may not start a foreground service from the background unless an exemption applies. Android's documentation lists exemptions such as a user tap on a notification or widget, an exact alarm for a user-requested action, and a high-priority FCM message. Any other start after the user has left the app throws.

For FCM the system can lower a high-priority message to normal, so read the priority the device actually received before starting the service.

Start from the exempt path only

override fun onMessageReceived(message: RemoteMessage) {
    if (message.priority == RemoteMessage.PRIORITY_HIGH) {
        ContextCompat.startForegroundService(this, Intent(this, SyncService::class.java))
    }
}

Crash from a plugin in Flutter or React Native

If the failing service belongs to a plugin, the plugin has to ship the type and permission. Update it or ask its maintainers: a manifest override cannot change how its code calls startForeground().

In short

  • Type in the manifest, matching permission, runtime rules: all three.
  • The exception class tells you which one is missing.
  • Start sensor services from a visible screen, not from the background.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want a second pair of eyes on it?

Send me the error and what changed before it started. I reply within 24 hours.