tezvyn:

What is the difference between a started service and a bound service?

AI-drafted, machine-checkedSource: developer.android.combeginner
What is the difference between a started service and a bound service?
WHAT IT TESTS

Android service lifecycle and IPC boundaries.

ANSWER OUTLINE

started services run until stopped via startService with no caller interface; bound services expose an IBinder and destroy when all clients unbind.

WHAT THIS TESTS: This question evaluates whether you understand the two fundamental service startup modes in Android and their lifecycle implications. Interviewers want to see that you know a service is not just a background task but a component with specific system contracts, and that you can choose the right pattern for long-running work versus client-server interaction within an app.

A GOOD ANSWER COVERS: First, define a started service as one initiated by startService which triggers onStartCommand. It runs indefinitely until it calls stopSelf or another component calls stopService, and the originating component does not receive a direct handle back. Second, define a bound service as one connected to via bindService which triggers onBind and returns an IBinder. It exists only while at least one client is bound; when all clients unbind, the system destroys it. Third, note that the two modes can coexist, a service can be both started and bound, but the question asks for clear separation. Fourth, give crisp use cases, a music player downloading a playlist in the background fits a started service, while an activity talking to a local music playback controller fits a bound service.

COMMON WRONG ANSWERS: Claiming that bound services continue running after all clients unbind. Saying that started services automatically stop when the starting activity finishes. Treating services as equivalent to background threads and ignoring that services run on the main thread by default. Failing to mention IBinder or onBind when describing bound services. Describing a use case that actually requires a foreground service but calling it a started service without mentioning the notification requirement on modern Android.

LIKELY FOLLOW-UPS: How would you convert a started service into a foreground service and why is that required for long-running tasks? What thread should heavy work run on inside a service? How do you handle multiple concurrent bind and unbind calls from rotating activities? Can a service be both started and bound simultaneously, and how does that affect its lifecycle? When should you use a WorkManager instead of either service type?

ONE CONCRETE EXAMPLE: For a started service, a file upload that must complete even if the user leaves the app. The service receives the file URI in onStartCommand, launches a worker thread, and calls stopSelf when the upload finishes. For a bound service, a calculator engine shared between three activities. Activity A binds to it to perform tax calculations, gets the IBinder, calls methods directly, and unbinds in onStop. When the last activity unbinds, the service is destroyed automatically.

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.