Gestire l'interruzione avviata dall'utente delle app che eseguono servizi in primo piano
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
A partire da Android 13 (livello API 33), gli utenti possono completare un flusso di lavoro dal
riquadro delle notifiche
per arrestare un'app con servizi in primo piano in esecuzione, indipendentemente dalla
versione SDK target dell'app. Questa funzionalità, chiamata
Task Manager, mostra un elenco di app che
attualmente eseguono un servizio in primo piano.
Figura 1. Flusso di lavoro di Task Manager sui dispositivi
con Android 13 o versioni successive.
Questo elenco è etichettato come App attive.
Accanto a ogni app è presente un pulsante Interrompi. La figura 1 illustra il flusso di lavoro di Task Manager su un dispositivo con Android 13.
Quando l'utente preme il pulsante Interrompi accanto alla tua app in
Task Manager, si verificano le seguenti azioni:
Il sistema rimuove l'app dalla memoria. Pertanto, l'intera app si arresta,
non solo il servizio in primo piano in esecuzione.
Il sistema rimuove lo stack delle attività dell'app.
La riproduzione di contenuti multimediali viene interrotta.
La notifica associata al servizio in primo piano viene rimossa.
L'app rimane nella cronologia.
I job pianificati vengono eseguiti all'orario programmato.
Le sveglie suonano all'ora o nell'intervallo di tempo programmati.
Per verificare che la tua app si comporti come previsto durante e dopo l'interruzione dell'app da parte di un utente, esegui questo comando ADB in una finestra del terminale:
adbshellcmdactivitystop-appPACKAGE_NAME
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,["Starting in Android 13 (API level 33), users can complete a workflow from the\n[notification drawer](/develop/ui/views/notifications#bar-and-drawer)\nto stop an app that has an ongoing foreground services, regardless of that app's\ntarget SDK version. This affordance, called the\n*Task Manager*, shows a list of apps that are\ncurrently running a foreground service. \n**Figure 1.** Task Manager workflow on devices that run Android 13 or higher.\n\nThis list is labeled **Active apps** .\nNext to each app is a **Stop** button. Figure 1 illustrates the\nTask Manager workflow on a device that runs\nAndroid 13.\n\nWhen the user presses the **Stop** button next to your app in the\nTask Manager, then the following actions occur:\n\n- The system removes your app from memory. Therefore, your **entire app stops**, not just the running foreground service.\n- The system removes your app's activity back stack.\n- Any media playback stops.\n- The notification associated with the foreground service is removed.\n- Your app remains in history.\n- Scheduled jobs execute at their scheduled time.\n- Alarms go off at their scheduled time or time window.\n\n| **Note:** The system doesn't send your app any callbacks when the user taps the **Stop** button. When your app starts back up, it's helpful to check for the [`REASON_USER_REQUESTED`](/reference/android/app/ApplicationExitInfo#REASON_USER_REQUESTED) reason that's part of the `ApplicationExitInfo` API.\n\nTo test that your app behaves as expected while and after a user stops your\napp, run the following ADB command in a terminal window: \n\n```bash\nadb shell cmd activity stop-app PACKAGE_NAME\n```"]]