Android 13 (API level 33) allows users to stop foreground services from the notification drawer, regardless of target SDK version. This new affordance, called the Foreground Services (FGS) Task Manager, shows a list of apps that are currently running a foreground service. This list is labeled Active apps. Next to each app is a Stop button. Figure 1 illustrates the FGS Task Manager workflow on a device that runs Android 13:
User action stops your entire app
When the user presses the Stop button next to your app in the FGS Task Manager, then your entire app stops, not just the running foreground service.
Comparing behavior with "swipe up" and "force stop" user actions
Refer to the following table to see how the FGS Task Manager compares to the existing affordances: "swipe up" from the Recents screen and "force stop" a misbehaving app.
FGS Task Manager | Swipe up | Force stop | |
---|---|---|---|
Immediately removes app from memory | ✔ | ✔ | |
Media playback is stopped | ✔ | ✔ | |
FGS stopped / Associated notification removed | ✔ | ✔ | |
Removes the activity back stack | ✔ | ✔ | ✔ |
Removes app from history | ✔ | ✔ | |
Scheduled jobs are canceled | ✔ | ||
Alarms are canceled | ✔ |
No callbacks sent when user stops app from FGS Task Manager
The system doesn't send your app any callbacks when the user presses the
Stop button. When your app starts back up, it might be helpful for you to
check for the new
REASON_USER_REQUESTED
reason that's part of the existing ApplicationExitInfo
API.
System prompts related to long-running foreground services
If the system detects that your app runs a foreground service for a long period of time—at least 20 hours within a 24-hour window—the system sends a notification to the user, inviting them to interact with the FGS Task Manager.
Learn more about the new system notification that alerts users to long-running foreground service.
Exemptions
The system provides several levels of exemptions for certain types of apps, which the following sections describe.
Exemptions are per app, not per process. If the system exempts one process in an app, all other processes in that app are also exempt.
Exemptions from appearing in the FGS Task Manager at all
The following apps can run a foreground service and not appear in the task manager at all:
- System-level apps
- Safety apps; that is, apps that have the
ROLE_EMERGENCY
role - Devices that are in demo mode
Exemptions from being stoppable by users
When the following types of apps run a foreground service, they appear in the FGS Task Manager, but there is no Stop button next to the app's name for the user to press:
- Device owner apps
- Profile owner apps
- Persistent apps
- Apps that have the
ROLE_DIALER
role
Testing
To test that your app is behaving as expected while and after a user stops your app, run the following ADB command in a terminal window:
adb shell cmd activity stop-app PACKAGE_NAME