Menghentikan layanan latar depan
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Jika Anda ingin layanan latar depan berhenti berjalan di latar depan, Anda memiliki
dua opsi. Anda dapat menghentikan layanan, atau membiarkan layanan
berjalan tetapi menghapusnya dari latar depan.
Anda dapat menghentikan layanan latar depan
dengan cara yang sama seperti menghentikan layanan lainnya. Layanan dapat
memanggil metode stopSelf()
-nya sendiri, atau komponen lain dapat menghentikannya
dengan memanggil stopService()
. Jika Anda menghentikan layanan saat berjalan
di latar depan, notifikasinya akan dihapus.
Untuk menghapus layanan dari latar depan, panggil
stopForeground(int)
dari dalam layanan. Metode ini menggunakan boolean, yang menunjukkan apakah notifikasi status bar juga akan dihapus. Layanan terus berjalan, tetapi
bukan lagi layanan latar depan.
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.
[null,null,["Terakhir diperbarui pada 2025-08-27 UTC."],[],[],null,["If you want a foreground service to stop running in the foreground, you have\ntwo options. You can stop the service, or you can leave the service\nrunning but remove it from the foreground.\n\nYou can stop a foreground service\n[the same way you would stop any service](/develop/background-work/services#Stopping). The service can\ncall its own [`stopSelf()`](/reference/android/app/Service#stopSelf()) method, or another component can stop it\nby calling [`stopService()`](/reference/android/content/Context#stopService(android.content.Intent)). If you stop the service while it runs\nin the foreground, its notification is removed.\n\nTo remove a service from the foreground, call\n[`stopForeground(int)`](/reference/android/app/Service#stopForeground(int))\nfrom inside the service. This method takes a boolean, which indicates whether to\nremove the status bar notification as well. The service continues to run, but\nit is no longer a foreground service."]]