Android Service vs IntentService

Android Service VS IntentService

Android Service vs IntentService

In this blog, we will explain about the Android Service vs IntentService. Service is a base class of service implementation and runs in the application’s main thread that may reduce the application’s performance while Intent Service is a direct subclass of Service that makes things easier. The Intent Services is used to perform the certain task in the background.

Service

A Service is an application component that can performing operations running longer times in the background and doesn’t provide a user interface. It represents an application’s desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.

There are the three different types of services:

  • Foreground
  • Background
  • Bound

1. Foreground:

A foreground service performs some operation that is noticeable to the user and continue running until the user is not interacting with the application. For example, an audio app use a foreground service to play an audio track.

2. Background:

In this, the user is not directly noticeable while it performs an operation. For example, if an application used a service to compact its storage, then it would usually a background service.

3. Bound:

In this, a service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface by which the components interact with the service, send requests, receive results, and even do more processes with interprocess communication (IPC) and run only as long as another applications component is bound to it.

IntentService

IntentService is a direct subclass of Service to make things easier and perform a certain task in the background. It creates a queue that passes one intent at a time to onHandleIntent(). Therefore, implementing a multi-thread made by extending Service class directly and this class needs a manual stop using stopSelf(). Therefore, Intent Service automatically stops itself after the executions has been finished.

IntentService can not be bound by default as it implements onBind() that returns null.

Intent Service implement onStartCommand() that sends the Intent to queue and to onHandleIntent().