Skip to content
tezvyn:
Menu

IntentService: Queued Background Work (Deprecated)

Source: developer.android.comEasyHow cards are made

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.

Interview question

Which characteristic best describes how IntentService handled multiple background work requests?

  • a.It processed all requests concurrently on separate worker threads.
  • b.It processed requests sequentially on a single worker thread, stopping when done.Correct
  • c.It required the developer to manually manage its lifecycle, including stopping it.
  • d.It allowed tasks to be scheduled with specific network and charging constraints.
Why?

IntentService was designed to process tasks one after another on a single worker thread, automatically stopping itself when the queue was empty. Options A, C, and D describe features it lacked or are characteristics of other background processing mechanisms like WorkManager.

Just read this? Test yourself on what you have been reading.

Read the original → developer.android.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.

See open roles