Ringkasan layanan latar depan
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Layanan latar depan memungkinkan Anda melakukan operasi secara asinkron yang
dapat dilihat oleh pengguna. Layanan latar depan menampilkan notifikasi status bar, agar pengguna tahu bahwa aplikasi Anda sedang menjalankan tugas di latar depan dan memakai resource sistem.
Contoh aplikasi yang menggunakan layanan latar depan meliputi:
- Aplikasi pemutar musik yang memutar musik di layanan latar depan. Notifikasi
mungkin menampilkan lagu yang sedang diputar.
- Aplikasi kebugaran yang merekam aktivitas lari pengguna di layanan latar depan, setelah
menerima izin dari pengguna. Notifikasi dapat menampilkan jarak yang telah ditempuh pengguna selama sesi kebugaran saat ini.
Gunakan layanan latar depan hanya saat aplikasi perlu menjalankan tugas yang dapat dilihat oleh pengguna, bahkan saat mereka tidak berinteraksi langsung dengan aplikasi. Jika tindakan memiliki kepentingan yang cukup rendah sehingga Anda ingin menggunakan notifikasi prioritas minimum, sebaiknya gunakan opsi pekerjaan latar belakang yang berbeda.
Panduan ini menjelaskan area berikut:
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-21 UTC.
[null,null,["Terakhir diperbarui pada 2025-08-21 UTC."],[],[],null,["# Foreground services overview\n\nForeground 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)"]]