フォアグラウンド サービスの概要
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
フォアグラウンド サービスを使用すると、ユーザーが認識できるオペレーションを非同期で実行できます。ステータスバーに通知を表示することにより、アプリがフォアグラウンドでタスクを実行していること、それに伴いシステム リソースが消費されていることにユーザーが気付けるようにします。
フォアグラウンド サービスを使用するアプリの例は次のとおりです。
- この音楽プレーヤー アプリは、フォアグラウンド サービスで音楽を再生します。通知として、いま再生中の曲が表示されます。
- このフィットネス アプリは、ユーザーからの許可を得たうえで、ユーザーのランニングをフォアグラウンド サービスで記録します。通知には、現在のフィットネス セッション中にユーザーが移動した距離が表示されることがあります。
フォアグラウンド サービスを使用する場合は、ユーザーがアプリを直接操作していないときでも、タスクが実行されていることに気付けるようにする必要があります。アクションの重要度が低く、最小優先度の通知を使用したい場合は、別のバックグラウンド作業オプションを使用することをおすすめします。
このガイドでは、次の領域について説明します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-21 UTC。
[null,null,["最終更新日 2025-08-21 UTC。"],[],[],null,["Foreground services let you asynchronously perform operations that are\nnoticeable to the user. Foreground services show a [status bar\nnotification](/develop/ui/views/notifications), to make users aware that your\napp is performing a task in the foreground and is consuming system resources.\n\nExamples of apps that use foreground services include the following:\n\n- A music player app that plays music in a foreground service. The notification might show the current song being played.\n- A fitness app that records a user's run in a foreground service, after receiving permission from the user. The notification might show the distance that the user has traveled during the current fitness session.\n\nOnly use a foreground service when your app needs to perform a task\nthat is noticeable by the user, even when they're not directly interacting with\nthe app. If the action is of low enough importance that you want to use a\nminimum-priority notification, you probably want to use a different\n[background work option](/develop/background-work/background-tasks).\n\nThis guide explains the following areas:\n\n- [Declare foreground services and request\n permissions](/develop/background-work/services/fgs/declare)\n- [Launch a foreground service](/develop/background-work/services/fgs/launch)\n- [Stop a foreground service](/develop/background-work/services/fgs/stop-fgs)\n- [Handle when a user stops an app that has a foreground\n service](/develop/background-work/services/fgs/handle-user-stopping)\n- [Restrictions on starting a foreground service from the background](/develop/background-work/services/fgs/restrictions-bg-start)\n- [Foreground service types](/develop/background-work/services/fgs/service-types)\n- [Foreground service timeout behavior](/develop/background-work/services/fgs/timeout)\n- [Foreground service troubleshooting](/develop/background-work/services/fgs/troubleshooting)\n- [Changes to foreground services](/develop/background-work/services/fgs/changes)"]]