نظرة عامة حول الخدمات التي تعمل في المقدّمة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك الخدمات التي تعمل في المقدّمة تنفيذ عمليات بشكل غير متزامن يلاحظها المستخدم. تعرض الخدمات التي تعمل في المقدّمة إشعارًا في شريط الحالة لإعلام المستخدمين بأنّ تطبيقك ينفّذ مهمة في المقدّمة ويستهلك موارد النظام.
في ما يلي أمثلة على التطبيقات التي تستخدم الخدمات التي تعمل في المقدّمة:
- تطبيق مشغّل موسيقى يشغّل الموسيقى في خدمة تعمل في المقدّمة قد يعرض الإشعار الأغنية التي يتم تشغيلها حاليًا.
- تطبيق لياقة بدنية يسجّل ركض المستخدم في خدمة تعمل في المقدّمة بعد الحصول على إذن منه قد يعرض الإشعار المسافة التي قطعها المستخدم أثناء جلسة اللياقة البدنية الحالية.
لا تستخدِم خدمة تعمل في المقدّمة إلا عندما يحتاج تطبيقك إلى تنفيذ مهمة يمكن للمستخدم ملاحظتها، حتى عندما لا يتفاعل مباشرةً مع التطبيق. إذا كان الإجراء غير مهم بما يكفي لاستخدام إشعار بأولوية دنيا، من الأفضل استخدام خيار آخر لتنفيذ العمل في الخلفية.
يشرح هذا الدليل الجوانب التالية:
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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)"]]