フォアグラウンド サービスを停止する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
フォアグラウンド サービスをフォアグラウンドで実行しないようにするには、次の 2 つの方法があります。サービスを停止するか、サービスを実行したままフォアグラウンドから削除できます。
フォアグラウンド サービスは、他のサービスを停止するのと同じ方法で停止できます。サービスは独自の stopSelf()
メソッドを呼び出すことができます。また、別のコンポーネントが stopService()
を呼び出してサービスを停止することもできます。フォアグラウンドで実行中にサービスを停止すると、通知が削除されます。
サービスをフォアグラウンドから削除するには、サービス内から stopForeground(int)
を呼び出します。このメソッドは、ステータスバーの通知も削除するかどうかを示すブール値を受け取ります。サービスは引き続き実行されますが、フォアグラウンド サービスではなくなります。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-27 UTC。
[null,null,["最終更新日 2025-08-27 UTC。"],[],[],null,["If you want a foreground service to stop running in the foreground, you have\ntwo options. You can stop the service, or you can leave the service\nrunning but remove it from the foreground.\n\nYou can stop a foreground service\n[the same way you would stop any service](/develop/background-work/services#Stopping). The service can\ncall its own [`stopSelf()`](/reference/android/app/Service#stopSelf()) method, or another component can stop it\nby calling [`stopService()`](/reference/android/content/Context#stopService(android.content.Intent)). If you stop the service while it runs\nin the foreground, its notification is removed.\n\nTo remove a service from the foreground, call\n[`stopForeground(int)`](/reference/android/app/Service#stopForeground(int))\nfrom inside the service. This method takes a boolean, which indicates whether to\nremove the status bar notification as well. The service continues to run, but\nit is no longer a foreground service."]]