---
title: "What is Intent service?"  
description: "What is Intent service?"  
author: "Prateek sharma"  
published: 2018-04-07  
canonical: https://answers.mindstick.com/qa/40996/what-is-intent-service  
category: "android"  
tags: ["android"]  
reading_time: 3 minutes  

---

# What is Intent service?

## Answers

### Answer by Arti Mishra

**Intent** Generally **intent is a message** that is pass between different [components](https://www.mindstick.com/interview/604/what-are-the-components-of-struts) such as activities, [content providers](https://answers.mindstick.com/qa/40987/what-are-content-providers-in-android-how-to-implement-this-in-a-program), [broadcast](https://www.mindstick.com/articles/1633/broadcastreceiver-in-android) receiver etc. It is **mainly used for invoked or called the [component](https://www.mindstick.com/interview/729/what-is-a-component)** such as-

- Dial a phone call
- Display a webpage
- Display our all contacts
- Launch an activity in our project
- Start any type of service
- Broadcast a message etc.

**How intent Work:** **\**![What is Intent service?](https://answers.mindstick.com/questionanswer/8032f5ad-a1f1-4ddd-aa8d-0ddaee991063/images/b577307a-5d7c-4430-98d0-729c91543652.png)Image Source**\** **\****Sending Data by using Intent Class**

```
Intent intent=new Intent (Context, Destination class);
Intent.putExtra(key,value);
startActivity(intent);
```

\
**Fetching Data After intent service is Completed-**

```
Intent intent=getIntent();
DataType variable=intent.getStringExtra(key);
```

\
**Intent Services:** IntentService is base class of Service class that handle asynchronous request or task on users demands. In android if client send any requests then startService(Intent) method calls. After processing all request it automatically stop the work. IntentService can handle multiple task simultaneously. In android when callback is needed then be use Intent. And if we cann’t communicate to Main Thread and perform log task then we use Intent Services after that if we want to communicate then we use Main Thread Handler.\
**The IntentService class provide the following services-**

- For executing all the intents it create a default worker thread that are delivered to startActivityCommand() method, and also attach your application’s main thread.
- After that we can create work queue & pass one intent at a time on your onHandleIntent() method for implementation & it also remove the concept of multi-threading.
- If all the start request are handled then stop the service, and you can never use stopSelf() method for stopping the services.
- For provides default implementation you can use onBind() method that returns null value.
- At last Provide the implementation of onStartCommand() method to sends the entent on work queue and handle the onHandleIntent() method.

Finally completing the whole work provided by the user, you can implement onHandleIntent() method. However, you can provide the constructor for the IntentService. **\**![What is Intent service?](https://answers.mindstick.com/questionanswer/8032f5ad-a1f1-4ddd-aa8d-0ddaee991063/images/2f962c3a-2d5d-4947-9863-49bc8292e869.png)**\**[Image Source](https://www.mindstick.com/forum/34428/how-to-remove-image-source-from-html-content)**\****\**

**Here's an example [implementation](https://www.mindstick.com/interview/733/what-is-implementation-and-interface-inheritance) of IntentService.**\

```
public class IntentServiceExample extends IntentService {
public  IntentServiceExample() {
  super(“IntentServiceExample”);
}
@override
protected void onHandleIntent(Intent intent) {
try  {
Thread.sleep(5000);
} catch(interruptedException e) {
Thread.currentThread().intrrupt();
}
}
}
```

If you want to override the different callback methods such as onCreate(), onDestroy(), onStartCommand() then you must implement the IntentService Class that handle the [functionality](https://www.mindstick.com/interview/547/explain-about-the-functionality-of-vb-script) of worker thread.\
**For Example –** onStartCommand() method return the implementation ,which describe how the intent is deliverd to onHandleIntent() method.

```
@override
Public int onStartCommand(Intent intent, int flag, int id) {
Toast.makeText(this,”Service Started”,Toast.LENGTH_LONG).show();
return.super.onStartCommand(intent, flag, id);
}
```

If [your service](https://yourviews.mindstick.com/view/84998/build-your-own-chatgpt-up-to-date-guide-at-your-service) allow binding then you can call onBind() method. \


---

Original Source: https://answers.mindstick.com/qa/40996/what-is-intent-service

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
