איך מפסיקים שירות שפועל בחזית
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
יש שתי אפשרויות להפסקת הפעולה של שירות בחזית: אפשר להפסיק את השירות או להשאיר אותו פעיל אבל להסיר אותו מהחזית.
אפשר להפסיק שירות שפועל בחזית באותה דרך שבה מפסיקים כל שירות אחר. השירות יכול להפעיל את השיטה stopSelf()
שלו, או שרכיב אחר יכול להפסיק אותו על ידי הפעלת השיטה stopService()
. אם מפסיקים את השירות בזמן שהוא פועל בחזית, ההתראה שלו מוסרת.
כדי להסיר שירות מהחזית, קוראים ל-stopForeground(int)
מתוך השירות. השיטה הזו מקבלת ערך בוליאני שמציין אם להסיר גם את ההתראה בשורת הסטטוס. השירות ממשיך לפעול, אבל הוא כבר לא שירות שפועל בחזית.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-27 (שעון UTC).
[null,null,["עדכון אחרון: 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."]]