IntentService is an extension of the Service component class that handles asynchronous requests (expressed as Intent s) on demand. Clients send requests through Context.
Service : is a component of android which performs long running operation in background, mostly with out having UI. Thread : is a O.S level feature that allow you to do some operation in the background.
IntentService runs on its own thread. It will stop itself when it's done.
It means when you are using IntentService once your application gets killed onHandleIntent() never execute till you will not start service again. For JobIntentService: After an application gets killed, after few seconds loop inside onHandleWork() starts executing but this time it starts from 0 loop count.
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
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, while IntentService
creates a worker thread and uses that thread to run the service.IntentService
creates a queue that passes one intent at a time to onHandleIntent()
. Thus, implementing a multi-thread should be made by extending Service
class directly.
Service
class needs a manual stop using stopSelf()
. Meanwhile, IntentService
automatically stops itself when it finishes execution. IntentService
implements onBind()
that returns null
. This means that the IntentService
can not be bound by default.IntentService
implements onStartCommand()
that sends Intent to queue and to onHandleIntent()
.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.
service: It runs in the background on your system. For example,
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.
See Tejas Lagvankar's post about this subject. Below are some key differences between Service and IntentService and other components.
Service
onStartService()
main(UI
) threadIntentService
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With