Stop a foreground service
Stay organized with collections
Save and categorize content based on your preferences.
If you want a foreground service to stop running in the foreground, you have
two options. You can stop the service, or you can leave the service
running but remove it from the foreground.
You can stop a foreground service
the same way you would stop any service. The service can
call its own stopSelf()
method, or another component can stop it
by calling stopService()
. If you stop the service while it runs
in the foreground, its notification is removed.
To remove a service from the foreground, call
stopForeground()
from inside the service. This method takes a boolean, which indicates whether to
remove the status bar notification as well. The service continues to run, but
it is no longer a foreground service.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-01-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-01-31 UTC."],[],[]]