توقف خدمات پیشزمینه، توقف خدمات پیشزمینه، توقف خدمات پیشزمینه
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
اگر می خواهید یک سرویس پیش زمینه در پیش زمینه متوقف شود، دو گزینه دارید. میتوانید سرویس را متوقف کنید، یا میتوانید سرویس را در حال اجرا رها کنید اما آن را از پیشزمینه حذف کنید.
شما می توانید یک سرویس پیش زمینه را به همان روشی که هر سرویسی را متوقف می کنید متوقف کنید. این سرویس می تواند متد stopSelf()
خود را فراخوانی کند، یا جزء دیگر می تواند با فراخوانی stopService()
آن را متوقف کند. اگر سرویس را در حالی که در پیش زمینه اجرا می شود متوقف کنید، اعلان آن حذف می شود.
برای حذف یک سرویس از پیش زمینه، با stopForeground(int)
از داخل سرویس تماس بگیرید. این روش یک بولی می گیرد که نشان می دهد اعلان نوار وضعیت نیز حذف شود. این سرویس همچنان به کار خود ادامه می دهد، اما دیگر یک سرویس پیش زمینه نیست.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]