In Android when collecting data using a sensor should I use IntentService or Service?

343 views Asked by At

I'm making an app that will collect data using a sensor, only when the device is on. This program will mainly run from the notification bar. Most of the posts about using sensors in the background seem to suggest using Service but I've read that IntentServices are the way to go if handling a long task. So I was wondering which one would be best to use?

1

There are 1 answers

0
Martin On BEST ANSWER

It sounds more like you would need a Service, as you will have a long-running operation (monitoring the sensors) which will pause (but not destroy) during some periods when the monitoring will not be required.

Using a Service will also allow your app's activities to bind to it, and show something like live updates. What you however need to be aware of is that if you would like to do something periodic in your Service then you will need to handle the scheduling and threading (if necessary, depending on the amount of processing required) yourself.

You could for example use an IntentService if you wanted to send the collected data to a remote server, as this will nicely kick off a worker thread for you to perform the (slow) network request on.