Panoramica dei servizi in primo piano
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I servizi in primo piano ti consentono di eseguire in modo asincrono operazioni che sono
visibili all'utente. I servizi in primo piano mostrano una notifica
della barra di stato per informare gli utenti che la tua
app sta eseguendo un'attività in primo piano e sta consumando risorse di sistema.
Ecco alcuni esempi di app che utilizzano i servizi in primo piano:
- Un'app di riproduzione musicale che riproduce musica in un servizio in primo piano. La notifica
potrebbe mostrare il brano attualmente in riproduzione.
- Un'app per il fitness che registra la corsa di un utente in un servizio in primo piano, dopo
aver ricevuto l'autorizzazione dall'utente. La notifica potrebbe mostrare la distanza
percorsa dall'utente durante la sessione di allenamento corrente.
Utilizza un servizio in primo piano solo quando la tua app deve eseguire un'attività
che l'utente può notare, anche quando non interagisce direttamente con
l'app. Se l'azione è di importanza sufficientemente bassa da voler utilizzare una
notifica con priorità minima, probabilmente ti conviene utilizzare un'altra
opzione di lavoro in background.
Questa guida illustra le seguenti aree:
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-08-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-08-27 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)"]]