IntentService: Queued Background Work (Deprecated)
IntentService was a simple tool for running background tasks sequentially. You sent it work as an Intent, it processed it on a worker thread, and shut down when done. It's now deprecated; use WorkManager for modern background jobs.
WHY IT EXISTS Standard Android Service components run on the main UI thread by default. To perform long-running operations without freezing the app, developers had to manually create and manage background threads. IntentService was created to abstract away this boilerplate for simple, sequential background tasks.
THE MENTAL MODEL Think of an IntentService as a dedicated, single-worker assembly line. You send parts (Intents) to the line. The worker picks up one part, processes it completely, then picks up the next. When there are no more parts in the queue, the worker goes home and the lights turn off (the service stops itself).
HOW IT WORKS You subclass IntentService and implement one method: onHandleIntent(Intent intent). When you call startService(intent), the system delivers the Intent to your service. IntentService automatically creates a worker thread and calls your onHandleIntent() on that thread. It queues multiple Intents, processing them sequentially. Once the queue is empty, the service automatically calls stopSelf().
WHEN TO USE IT Historically, it was used for tasks that could be done in the background, didn't require user interaction, and could be executed one after another. Examples include logging analytics, downloading non-critical assets, or syncing small amounts of data with a server.
WHEN NOT TO USE IT Do not use IntentService in new code; it is deprecated as of API 30. For any new background task, use WorkManager. WorkManager is lifecycle-aware, can handle constraints (like network or charging status), and offers more robust policies for retries and guaranteed execution. Also, IntentService was never suitable for tasks that needed to run in parallel, as it processes all requests serially.
ONE CANONICAL EXAMPLE A classic use case was an app that needed to upload a user's photo to a server. The UI would create an Intent containing the photo's URI and start an IntentService. The service would receive the intent, process the photo (compress it), and upload it on its background thread. The user could navigate away from the upload screen, and the work would continue until finished.
Read the original → developer.android.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.