Android Service, IntentService (Note)

Jin Cui
Jin Cui
Aug 31, 2018 · 1 min read

Service is used to perform a long-run task, but it is not running on background thread by default, it’s developer’s job to spawn a thread to execute the task. With that said, Service is just a regular component in Android like Activity.

Android provides an easy way to use Service, which is IntentService, it offers a method onHandleIntent, android system will create a worker thread for you to run onHandleIntent() function, and once the task is done, Android stops the service automatically.

How to communicate between service and activity,

  1. intent data, the intent data gets passed in when the service is created
  2. use broadcast receiver, don’t forget to explicitly call registerReceiver

Jin Cui

Written by

Jin Cui

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade