Service هو مكون Android لتنفيذ العمليات بدون واجهة مستخدم — عادة ما يكون للعمل طويل المدى في الخلفية. هناك أنواع مختلفة (foreground و background و bound)، كل منها مناسب لاحتياجات مختلفة، رغم أن نظام Android الحديث يفضل WorkManager في العديد من الحالات.
ما هي الـ Service
A SERVICE runs operations WITHOUT a UI (not tied to a screen):
→ for work that should continue regardless of UI (or independent of any activity)
→ declared in the manifest; runs in the app's process (main thread by default — must
move heavy work off it!)
أنواع الخدمات
FOREGROUND SERVICE → user-aware, ongoing work with a PERSISTENT NOTIFICATION:
→ music playback, navigation, active location tracking, ongoing downloads
→ higher priority (less likely to be killed); the notification is required
BACKGROUND SERVICE → work without user awareness:
→ heavily RESTRICTED on modern Android (battery) → often use WorkManager instead
BOUND SERVICE → other components BIND to it for a client-server interface (interact with
it, call methods); lives while bound
