Perubahan pada layanan latar depan
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dokumentasi layanan latar depan menjelaskan perilaku layanan latar depan Android saat ini. Dokumentasi ini memberikan panduan tentang praktik terbaik untuk sebagian besar aplikasi, baik yang menargetkan versi Android terbaru maupun tidak.
Halaman ini menjelaskan beberapa perubahan penting terbaru pada layanan latar depan, dan implikasinya bagi aplikasi yang tidak menargetkan versi terbaru platform Android. Dalam banyak kasus, praktik terbaik yang bersifat opsional untuk aplikasi yang menargetkan level API yang lebih rendah menjadi wajib untuk aplikasi yang menargetkan level API yang lebih tinggi.
Android 16 (level API 36)
Perubahan berikut berlaku untuk aplikasi yang berjalan di Android 16 atau yang lebih tinggi, terlepas dari level API yang ditargetkan:
Tugas latar belakang yang dimulai dari layanan latar depan kini harus mematuhi kuota runtime masing-masing. Hal ini mencakup tugas yang dijadwalkan langsung dengan
JobScheduler
, serta tugas yang dibuat oleh library lain seperti
WorkManager atau DownloadManager
.
Untuk mentransfer data sebagai respons terhadap tindakan pengguna, pertimbangkan untuk menggunakan
tugas transfer data yang dimulai oleh pengguna. Pekerjaan ini dikecualikan dari
kuota pekerjaan biasa.
Android 15 (level API 35)
Persyaratan berikut berlaku untuk aplikasi yang menargetkan level API 35 atau yang lebih tinggi:
Android 14 (level API 34)
Persyaratan berikut berlaku untuk aplikasi yang menargetkan level API 34 atau yang lebih tinggi:
- Anda harus menyatakan semua layanan latar depan dengan jenis layanannya.
- Aplikasi harus meminta jenis izin yang sesuai untuk jenis pekerjaan yang akan dilakukan layanan latar depan. Setiap jenis layanan latar depan
memiliki jenis izin yang sesuai. Misalnya, jika aplikasi meluncurkan
layanan latar depan yang menggunakan kamera, Anda harus meminta izin
FOREGROUND_SERVICE
dan
FOREGROUND_SERVICE_CAMERA
. Jika
aplikasi menargetkan API level 34 atau yang lebih tinggi dan tidak
meminta izin spesifik yang sesuai, sistem akan menampilkan
SecurityException
.
Android 12 (level API 31)
Persyaratan berikut berlaku untuk aplikasi yang menargetkan level API 31 atau yang lebih tinggi:
Android 11 (level API 30)
Persyaratan berikut berlaku untuk aplikasi yang menargetkan level API 30 atau yang lebih tinggi:
Android 10 (level API 29)
Persyaratan berikut berlaku untuk aplikasi yang menargetkan level API 29 atau yang lebih tinggi:
Android 9 (level API 28)
Android 9 memperkenalkan izin
FOREGROUND_SERVICE
. Aplikasi yang berjalan di
Android 9 yang menggunakan layanan latar depan harus memiliki izin tersebut.
Jika aplikasi yang menargetkan level API 28 atau yang lebih tinggi mencoba
membuat layanan latar depan tanpa meminta izin FOREGROUND_SERVICE
, sistem akan memunculkan SecurityException
.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-08-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-27 UTC."],[],[],null,["The foreground service documentation describes the current behavior of\nAndroid foreground services. The documentation gives guidance on best\npractices for most apps, whether or not they target the most recent version\nof Android.\n\nThis page describes some of the most recent important changes to foreground\nservices, and the implications for apps that aren't targeting the most\nrecent version of the Android platform. In many cases, best practices that\nwere optional for apps targeting lower API levels become mandatory for apps\nthat target higher API levels.\n\nAndroid 16 (API level 36)\n\nThe following changes apply to apps that run on Android 16 or higher,\nregardless of what API level they target:\n\n- Background jobs started from a foreground service now must adhere to their\n respective runtime quotas. This includes jobs scheduled directly with\n [`JobScheduler`](/reference/android/app/job/JobScheduler), as well as jobs created by other libraries like\n [WorkManager](/develop/background-work/background-tasks/persistent) or [`DownloadManager`](/reference/android/app/DownloadManager).\n\n To transfer data in response to a user action, consider using a\n [user-initiated data transfer job](/develop/background-work/background-tasks/uidt). These jobs are exempt from the\n ordinary job quotas.\n\nAndroid 15 (API level 35)\n\nThe following requirements apply to apps that target API\nlevel 35 or higher:\n\n- There are new restrictions on how long a `dataSync` foreground service can run. These restrictions are described in [Foreground service timeout\n behavior](/develop/background-work/services/fgs/timeout). Similar restrictions apply to the (new in Android 15) `mediaProcessing` foreground service type.\n- [`BOOT_COMPLETED` foreground services are no longer allowed to launch certain\n foreground services](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n- Apps that hold the `SYSTEM_ALERT_WINDOW` permission are only allowed to launch foreground services from the background if they currently have a visible overlay window (or if they meet one of the other [exemptions from background\n start restrictions](/develop/background-work/services/fgs/restrictions-bg-start#background-start-restriction-exemptions)). Previously, the exemption for those apps was broader.\n\nAndroid 14 (API level 34)\n\nThe following requirements apply to apps that target API\nlevel 34 or higher:\n\n- You must [declare all foreground services](/develop/background-work/services/fgs/declare) with their service types.\n- Apps must request the appropriate permission type for the kind of work the foreground service will be doing. Each [foreground service type](/develop/background-work/services/fgs/service-types) has a corresponding permission type. For example, if an app launches a foreground service that uses the camera, you must request both the [`FOREGROUND_SERVICE`](/reference/android/Manifest.permission#FOREGROUND_SERVICE) and [`FOREGROUND_SERVICE_CAMERA`](/reference/android/Manifest.permission#FOREGROUND_SERVICE_CAMERA) permissions. If an app targets API level 34 or higher and doesn't request the appropriate specific permission, the system throws a `SecurityException`.\n\nAndroid 12 (API level 31)\n\nThe following requirements apply to apps that target API\nlevel 31 or higher:\n\n- Apps are not allowed to launch foreground services while the app is in the background, with a few specific exceptions. For more information, and information about the exceptions to this rule, see [Restrictions on starting\n a foreground service from the background](/develop/background-work/services/fgs/restrictions-bg-start).\n\nAndroid 11 (API level 30)\n\nThe following requirements apply to apps that target API\nlevel 30 or higher:\n\n- If an app's foreground services use the camera or microphone, the app must [declare the service](/develop/background-work/services/fgs/declare) with the [`camera`](/develop/background-work/services/fgs/service-types#camera) or [`microphone`](/develop/background-work/services/fgs/service-types#microphone) service type, respectively.\n\nAndroid 10 (API level 29)\n\nThe following requirements apply to apps that target API\nlevel 29 or higher:\n\n- If an app's foreground services use location information, the app must [declare the service](/develop/background-work/services/fgs/declare) with the [`location`](/develop/background-work/services/fgs/service-types#location) service type.\n\nAndroid 9 (API level 28)\n\nAndroid 9 introduces the\n[`FOREGROUND_SERVICE`](/reference/android/Manifest.permission#FOREGROUND_SERVICE) permission. Apps running on\nAndroid 9 that use foreground services must have that permission.\n\nIf an app that targets API level 28 or higher attempts\nto create a foreground service without requesting the `FOREGROUND_SERVICE`\npermission, the system throws a [`SecurityException`](/reference/java/lang/SecurityException)."]]