Intent Service: Don’t reinvent the wheel.
This is a re-post of an answer I wrote on Stackoverflow.
IntentService extends Service class which clearly means that
IntentService is intentionally made for the 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 (
- Destroying the
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
Service class. So don't reinvent the wheel because
IntentService is the invented wheel.
The “Main” difference
The Service runs on the UI thread while an IntentService runs on a separate thread
When do you use IntentService?
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
A normal service runs on the UI Thread(Any Android Component type runs on UI thread by default eg
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
IntentService is given some default implementation which does those tasks for you.
According to the developer page
IntentServicecreates a Worker Thread
IntentServicecreates a Work Queue which sends the request to
onHandleIntent()method one by one
- When there is no work then
- Provides default implementation for
onBind()the method which is null
- Default implementation for
Intentrequest to WorkQueue and eventually to
Putting up content takes a lot of time and effort 😓.
👏 clap 👏 If you think you learned something from this article.You can find me on Stackoverflow,Github,and,on Linkedin.
Give feedback and feel free to correct mistakes.