---
title: "what is a service and how many types of service are there?"  
description: "what is a service and how many types of service are there?"  
author: "Prateek sharma"  
published: 2018-04-07  
updated: 2018-04-10  
canonical: https://answers.mindstick.com/qa/41001/what-is-a-service-and-how-many-types-of-service-are-there  
category: "android"  
tags: ["android"]  
reading_time: 4 minutes  

---

# what is a service and how many types of service are there?

what is a [service](https://answers.mindstick.com/qa/33514/by-default-when-a-service-declared-in-the-androidmanifest-in-which-thread-will-it-run) and how many types of service are there?

## Answers

### Answer 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

onStartCommand()

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.

onBind()

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.\

\
onCreate()

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.

onDestroy()

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

### Answer 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?](https://answers.mindstick.com/questionanswer/1f10d75f-65ba-4d82-8ef3-5fa1a0b29b0c/images/92bbfc97-564f-4b61-aa72-f76eb367e247.png)Image Source**\**\
**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. \


---

Original Source: https://answers.mindstick.com/qa/41001/what-is-a-service-and-how-many-types-of-service-are-there

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
