what is a service and how many types of service are there?

0 votes
Prateek sharma asked 07-Apr-2018 in Android by Prateek sharma
edited 10-Apr-2018 by Harsh-Srivastava

what is a service and how many types of service are there?

2 Answer

1 votes
Arti Mishra answered 10-Apr-2018 by Arti Mishra
Android Service:
In android, service is a background process that run on a long duration of times. It is an application component that can perform different operations like handle network transactions, playing audio and video, perform file I/O, interact with a content provider etc. and it does not provide any user interface. Android services continues run in the background even if the user switches to another application it remain same. Android services are run on high priority than inactive or invisible activities. It can also be configured to restarted if it terminated by the android system.

Life Cycle of android Services:

what is a service and how many types of service are there?

Types of Services:
These are the three different types of services:
1. Foreground
2. Background
3. Bound
4. Started
5. Hybrid

Foreground Services:
Foreground services are those services that perform some operation that is noticeable to the user. For example, if we play any audio app then this type of app uses foreground services. Foreground services always display a notification & continue running even the user isn’t interact with the app.

Background Services:
Background service are those service that is not display the user. For providing straight forward structure we using IntentService for background thread. It allow to handle  long-running operation without affecting user task.

Bound Services:
When our application component binds, by calling bindService() method then it is called bound service. Bound Service allows component to interact with client-server interface for sending request, receive results etc. If another application component is bound then it run as long times and multiple components can bind to the service at once if they are unbind, the service is completely destroyed.

Started Service:
startService() method is used to start the service when other application components has been started and it is run continuously in the background. A started service does not have any clients to directly bound it unlike bound service. For this reason started service is launch. And finally started component are distroyed.

Hybrid Service:
A hybrid service are those service that contain the feature of both started service and bound service. A hybrid service is started when any event trigger or when any component bind to it. Another component or client component can’t be bound to the hybrid service. And it have no more clients to bound it.

PawanShukla commented 10-Apr-2018 by PawanShukla
Wow great it very informative information about android service.
0 votes
Shilpi  Nandi answered 12-Apr-2018 by Shilpi Nandi

A service is always running in background. Its an component that can run for long-run without needing interaction with the user.While the service for one application running in background,we can start other activity's service with that one. A component can bind and interact and even perform ipc. Service can handle play music, interact with content provider etc.

Types Of services


The system invokes this method by calling startService() when another component (such as an activity) requests that the service be started. When this method executes, the service is started and can run in the background indefinitely. If you implement this, it is your responsibility to stop the service when its work is complete by calling stopSelf() or stopService(). If you only want to provide binding, you don't need to implement this method.


The system invokes this method by calling bindService() when another component wants to bind with the service (such as to perform RPC). In your implementation of this method, you must provide an interface that clients use to communicate with the service by returning an IBinder. You must always implement this method; however, if you don't want to allow binding, you should return null.


The system invokes this method to perform one-time setup procedures when the service is initially created (before it calls either onStartCommand() or onBind()). If the service is already running, this method is not called.


The system invokes this method when the service is no longer used and is being destroyed. Your service should implement this to clean up any resources such as threads, registered listeners, or receivers. This is the last call that the service receives

PawanShukla commented 12-Apr-2018 by PawanShukla
the types of services you have mentioned are wrong. you have mention the life cycles method.