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

**Code:** `startForeground not called` · **Category:** Android · **Seen on:** Android

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.

## 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

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/android/foreground-service-did-not-call-startforeground)
