Can you please help me understand what the difference between an IntentService
and a Service
is?
-
2http://techtej.blogspot.com.es/2011/03/android-thread-constructspart-4.html – Pratik Butani Jan 17 '14 at 05:59
-
6Really good comparison here: http://stackoverflow.com/questions/15524280/service-vs-intent-service – Moemars Jun 16 '14 at 00:57
-
1Please go to the above links they are really TOO GOOD.. very big thanks for them... – Renjith K N Jul 31 '14 at 06:42
-
1How is an older question a duplicate of a newer one? – Ojonugwa Jude Ochalifu Apr 27 '17 at 10:19
8 Answers
Service
is a base class of service implementation. Service
runs on the application's main thread which may reduce the application performance. Thus, IntentService
, which is a direct subclass of Service is available to make things easier.
The IntentService
is used to perform a certain task in the background. Once done, the instance of IntentService
terminates itself automatically. Examples for its usage would be to download a certain resource from the Internet.
Differences
Service
class uses the application's main thread, whileIntentService
creates a worker thread and uses that thread to run the service.IntentService
creates a queue that passes one intent at a time toonHandleIntent()
. Thus, implementing a multi-thread should be made by extendingService
class directly.Service
class needs a manual stop usingstopSelf()
. Meanwhile,IntentService
automatically stops itself when it finishes execution.IntentService
implementsonBind()
that returnsnull
. This means that theIntentService
can not be bound by default.IntentService
implementsonStartCommand()
that sends Intent to queue and toonHandleIntent()
.
In brief, there are only two things to do to use IntentService
. Firstly, to implement the constructor. And secondly, to implement onHandleIntent()
. For other callback methods, the super is needed to be called so that it can be tracked properly.

- 5,669
- 9
- 46
- 84

- 4,177
- 4
- 27
- 41
-
Nice Explaination. I am making Music app. So, which one be nice for it? Service or IntentService ? – Shreyash Mahajan Jun 06 '13 at 09:57
-
11for music app i think you have to use Service because, as default, IntentService is unbinddable and, i think, you have to bind your music app with music service to start, to stop. As already said, IntentService is better for "start and forget" – Premier Jul 10 '13 at 05:57
-
@Premier Wouldn't IntentService be similar to Service.START_NOT_STICKY? As that is also "start and forget" according to your example. – IgorGanapolsky Oct 29 '13 at 18:42
-
i have an app which can sync data after some time through service so what should i use Service or Intent Service ? – M.Raheel Sep 25 '14 at 09:55
-
@M.Raheel Syncing data can result in long running operation, so i think you should use `IntentService` for your work – Kushal Sep 05 '16 at 11:32
-
@Jashan PJ Can you explain why `IntentService` cannot be bound from any component? – Kushal Sep 05 '16 at 11:40
-
Are you sure Service runs on main thread? I can create and run it in another one – Andrés Quiroz Valdovinos May 27 '20 at 14:22
In short, a Service is a broader implementation for the developer to set up background operations, while an IntentService is useful for "fire and forget" operations, taking care of background Thread creation and cleanup.
From the docs:
Service A Service is an application component representing either 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.
IntentService
Service is a base class for IntentService Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent)
calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.
Refer this doc - http://developer.android.com/reference/android/app/IntentService.html
-
9IntentService is not base class of Services. Reverse of it is true. Check - http://developer.android.com/reference/android/app/IntentService.html – Darpan Nov 12 '14 at 10:34
-
6@Darpan It is a base class for "Services that handle asynchronous requests", not for simply "Services". That's why the sentence above is correct. – afrish Jan 14 '15 at 20:14
-
Hi all, can i write an IntentService within a Service? If yes, can anyone please provide an example/code snippet. Thanks – Kaveesh Kanwal Feb 27 '15 at 07:24
-
2@Phix i am making an app in which i need to scan the local database in every half an hour which would be better IntentService or Service ?? – Sagar Devanga Mar 14 '15 at 07:10
service: It runs in the background on your system. For example,
- If you went to a hotel and you give your order for a soup to a server
- The server gets your order and sends to chef
- You don't know how the soup is made in the kitchen and what processes are required for making the soup
- Once your order is ready, the server brings you the soup.
background process: chef making soup
IntentService:- it's consecutive service.. (i.e) when you order many food items at a time to server but the server delivers those items one by one and not deliver them all at once.

- 26,627
- 26
- 120
- 132

- 1,641
- 15
- 13
-
8
-
4
-
-
3This explanation is incorrect. A `service` does not run in background but in the foreground. – krtkush Dec 07 '17 at 07:58
-
Service
- Task with no UI,but should not use for long Task. Use Thread within service for long Task
- Invoke by
onStartService()
- Triggered from any Thread
- Runs On Main Thread
- May block
main(UI
) thread
IntentService
- Long task usually no communication with main thread if communication is needed then it is done by Handler or broadcast
- Invoke via Intent
- triggered from Main Thread (Intent is received on main Thread and worker thread is spawned)
- Runs on separate thread
- We can't run task in parallel and multiple intents are Queued on the same worker thread.

- 5,669
- 9
- 46
- 84

- 3,674
- 27
- 36
Service
runs actually in the same thread of your app; when you extends Service, you must manually spawn new threads to run CPU blocking operations.
vs
IntentService
is a subclass of Service
which spawns a thread to do background work from there(No need to create a new thread to do CPU blocking operations).

- 2,855
- 21
- 30
-
isn't it to prevent CPU blocking operations, not run them? Im not sure though – committedandroider Nov 20 '14 at 06:32
-
thats true, service neew a new thread to run CPU blocking operations – raditya gumay Aug 18 '16 at 02:45
Service
: Works in the main thread so it will cause an ANR (Android Not Responding) after a few seconds.
IntentService
: Service
with another background thread working separately to do something without interacting with the main thread.

- 4,732
- 9
- 39
- 54

- 1,084
- 13
- 14
-
2*Service: Works in the main thread so it will cause an ANR (Android Not Responding) after a few seconds.* - I can have a service running for hours and hours and I've never seen an ANR, so I doubt that is true. – Tim Nov 10 '15 at 09:39
Intent service is child of Service
IntentService: If you want to download a bunch of images at the start of opening your app. It's a one-time process and can clean itself up once everything is downloaded.
Service: A Service which will constantly be used to communicate between your app and back-end with web API calls. Even if it is finished with its current task, you still want it to be around a few minutes later, for more communication

- 2,152
- 1
- 28
- 28