Android Service, IntentService (Note)
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,
- intent data, the intent data gets passed in when the service is created
- use broadcast receiver, don’t forget to explicitly call
registerReceiver
