I am seeking an example of something that can be done with an IntentService
that cannot be done with a Service
(and vice-versa)?
I also bel
IntentService extends Service class which clearly means that IntentService
is intentionally made for same purpose.
So what is the purpose ?
`IntentService's purpose is to make our job easier to run background tasks without even worrying about
Creation of worker thread
Queuing the processing multiple-request one by one (Threading
)
Service
So NO, Service
can do any task which an IntentService
would do. If your requirements fall under the above-mentioned criteria, then you don't have to write those logics in the Service
class.
So don't reinvent the wheel because IntentService
is the invented wheel.
The Service runs on the UI thread while an IntentService runs on a separate thread
When you want to perform multiple background tasks one by one which exists beyond the scope of an Activity then the IntentService
is perfect.
IntentService
is made from Service
A normal service runs on the UI Thread(Any Android Component type runs on UI thread by default eg Activity
, BroadcastReceiver
, ContentProvider
and Service
). If you have to do some work that may take a while to complete then you have to create a thread. In the case of multiple requests, you will have to deal with synchronization
.
IntentService
is given some default implementation which does those tasks for you.
According to developer page
IntentService
creates a Worker Thread
IntentService
creates a Work Queue which sends request to onHandleIntent()
method one by one
IntentService
calls stopSelf()
methodonBind()
method which is nullonStartCommand()
which sends Intent
request to WorkQueue and eventually to onHandleIntent()