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