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 (Threading)
  • Destroying the 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 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.

How 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 the developer page

  1. IntentService creates a Worker Thread
  2. IntentService creates a Work Queue which sends the request to onHandleIntent() method one by one
  3. When there is no work then IntentService calls stopSelf() method
  4. Provides default implementation for onBind() the method which is null
  5. Default implementation for onStartCommand() which sends Intent request to WorkQueue and eventually to onHandleIntent()
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.

--

--

--

Android Developer | Arizona State University | NASA Psyche Research Aide

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

We BUIDL and will keep BUIDL-ing

Spool Master Contract Paused — Update and Next Steps

Rocket Launchpad x Satoshi Club AMA Recap from 6th of August

https://t.co/HJbOH4M5Yi

Multi-company fleet management: moving towards smoother communication & maintenance planning in…

Apache Nifi Installation

Using Contract Testing and Cypress To Replace WebDriver at CM

CXL Institute — Digital Analytics Minidegree Program — Review

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rohit Singh

Rohit Singh

Android Developer | Arizona State University | NASA Psyche Research Aide

More from Medium

Expert: Courier App MVVM Jetpack (HMS Push Kit Uplink Message) in Android using Kotlin- Part-4

An Overview of HMS Core and Kits available on the Platform

Foldable Devices Android An Initiative

ExoPlayer playlist diffing