Introduction
Services are components that run without a user interface and have a conceptual affinity toward long-running processes. They are separate from notifications in the status bar or a Toast. Services can be started by application or bound by the application.
Services have two flavors: foreground services and background services.
Foreground Services
The intrinsic functioning of the foreground services differs with different versions. A foreground service follows a special notation and receive improved attention from the OS, making them less like to be killed because of a resource shortage.
Before Android 8.0, there were services that just presented a notification entry in the status bar. The client component that needs to use a service doesn't know whether the service that started is a foreground service. It just starts service with startService.
Then they run with the user being made aware of them. They must interfere with the operating system via notification in the status bar. A client component explicitly starts a foreground service itself.
Characteristics of foreground service are that it is less likely to be killed by Android because of the available shortage.
Background Services
Background services run in the background and will not show an entry in the status bar. They allowed using toasts to send short notification messages to users. Background services are more brittle compared to foreground services to user activities to kill them when there is a resource shortage.
The app has a visible activity currently active or paused.
The app has a foreground service, or the service is startForeground() at its operation.
Another foreground app is connected by using one of its services or by the content provider.
Declaring services
- <? xml version="1.0" encoding = "utf-8"?>
- <mnifest ..>
- <application ..>
- <activity ..>
- </activity ..>
- <service
- android:name = ".MyService"
- android:enabled = "true"
- android:exported = "true" >
- </service>
- </application>
- </maifest>
Name is a service class and it uses a dot at first character and prepends it with the name of the package specified in the manifest element. Enabled is either true or false and its default value is true or else the service is effectively disabled. Exported specifies other application can use the service and the default value is set to false.

Join the conversation! Your thoughts help the community grow.