The foreground service documentation describes the current behavior of Android foreground services. The documentation gives guidance on best practices for most apps, whether or not they target the most recent version of Android.
This page describes some of the most recent important changes to foreground services, and the implications for apps that aren't targeting the most recent version of the Android platform. In many cases, best practices that were optional for apps targeting lower API levels become mandatory for apps that target higher API levels.
Android 9 (API level 28)
Android 9 introduces the
FOREGROUND_SERVICE
permission. Apps running on
Android 9 that use foreground services must have that permission.
If an app that targets API level 28 or higher attempts
to create a foreground service without requesting the FOREGROUND_SERVICE
permission, the system throws a SecurityException
.
Android 10 (API level 29)
The following requirements apply to apps that target API level 29 or higher:
- If an app's foreground services use location information, the app must
declare the service with the
location
service type.
Android 11 (API level 30)
The following requirements apply to apps that target API level 30 or higher:
- If an app's foreground services use the camera or microphone, the app must
declare the service with the
camera
ormicrophone
service type, respectively.
Android 12 (API level 31)
The following requirements apply to apps that target API level 31 or higher:
- Apps are not allowed to launch foreground services while the app is in the background, with a few specific exceptions. For more information, and information about the exceptions to this rule, see Restrictions on starting a foreground service from the background.
Android 14 (API level 34)
The following requirements apply to apps that target API level 34 or higher:
- You must declare all foreground services with their service types.
- Apps must request the appropriate permission type for the kind of work the
foreground service will be doing. Each foreground service type
has a corresponding permission type. For example, if an app launches a
foreground service that uses the camera, you must request both the
FOREGROUND_SERVICE
andFOREGROUND_SERVICE_CAMERA
permissions. If an app targets API level 34 or higher and doesn't request the appropriate specific permission, the system throws aSecurityException
.
Android 15 (API level 35)
The following requirements apply to apps that target API level 35 or higher:
- There are new restrictions on how long a
dataSync
foreground service can run. These restrictions are described in Foreground service timeout behavior. Similar restrictions apply to the (new in Android 15)mediaProcessing
foreground service type. BOOT_COMPLETED
foreground services are no longer allowed to launch certain foreground services.- Apps that hold the
SYSTEM_ALERT_WINDOW
permission are only allowed to launch foreground services from the background if they currently have a visible overlay window (or if they meet one of the other exemptions from background start restrictions). Previously, the exemption for those apps was broader.