An Android service is an application component that does work without providing a user interface. Another component starts it or binds to it, and it keeps running even when the user switches to another app, subject to the system's background limits. A service runs on the main thread of your app process by default, so any blocking work must be moved to a background thread or coroutine.
Services are often misunderstood as "background threads". They are not: a service is a component that tells the system your process still has work to do. Since Android 8.0 (API 26) the system restricts background services heavily, so choosing the right type matters more than it used to.
| Kind | Started with | Typical use | Visible to user |
|---|---|---|---|
| Started service | startService() or startForegroundService() | One-off task that finishes by itself | No, unless foreground |
| Foreground service | startForegroundService() plus startForeground() | Music playback, navigation, ongoing uploads | Yes, a notification is required |
| Bound service | bindService() | Client-server interface inside or across apps | No |
A service can be both started and bound at the same time. The system keeps it alive until it has been stopped and every client has unbound.
A started service moves through onCreate(), then onStartCommand() for every start request, and finally onDestroy() after stopSelf() or stopService() is called. A bound service goes through onCreate(), onBind() when the first client binds, onUnbind() when the last client leaves, and onDestroy().
onStartCommand() returns a constant that tells the system what to do if it kills the process:
START_STICKY: recreate the service, with a null intent.START_NOT_STICKY: do not recreate it unless there are pending intents.START_REDELIVER_INTENT: recreate it and redeliver the last intent.Declare the service in the manifest, then subclass Service. This example does its work on a coroutine so the main thread stays free.
The service calls stopSelf(startId) when the work ends, so it does not keep the process alive for nothing. Returning null from onBind() means clients cannot bind to it. Set android:exported="false" unless other apps must start it.
A foreground service shows an ongoing notification, which gives it a higher priority so the system is much less likely to kill it. Since Android 8.0 you must start it with startForegroundService() and call startForeground() within a few seconds.
On Android 14 (API 34) and higher you must also declare a foreground service type in the manifest, such as mediaPlayback, location or dataSync, and request the matching permission. Android 15 adds time limits for some types such as dataSync, so check the current documentation for the type you use.
The notification channel sync_channel must exist first, and on Android 13 and higher the user must grant the notification permission for the notification to be shown.
A bound service exposes an interface that clients call directly. For a service inside your own process, return a Binder that gives access to the service instance.
The client calls bindService(intent, connection, Context.BIND_AUTO_CREATE) and receives the binder in ServiceConnection.onServiceConnected(). It must call unbindService() when finished, typically in onStop(). For other processes use a Messenger or AIDL.
For deferrable work that must finish even if the app is closed, such as uploading logs, use WorkManager. It chooses a safe execution mechanism and respects battery limits. Use a coroutine in a ViewModel for work tied to a screen. Use a service when the work must continue while the user is doing something else, or when you need a long-lived component that other components bind to.
No. A service runs on the main thread of its hosting process unless you declare android:process for it. Move blocking work to a coroutine, executor or thread.
An activity has a screen and is tied to user interaction. A service has no screen and represents work or an API that continues while the user is elsewhere.
IntentService was deprecated in API 30. Use WorkManager for deferrable tasks or a regular service with coroutines.
Since Android 8.0 an app in the background cannot freely start background services. Use a foreground service where an exemption applies, or WorkManager.
A service is a component for work without a user interface, either started, foreground or bound. It runs on the main thread, so offload work and stop it with stopSelf() when done. Use a foreground service with a notification and the right type for user-visible long tasks, and prefer WorkManager for deferrable background work.