Thawda
Thawda

Reputation: 97

Accelerometer in Service

I am trying to use the accelerometer in Service (to run in background indefinitely) for taking accelerometer data for my research group.

public class AccService extends Service implements SensorEventListener

My Question is that when I register the sensor, should I pass the registerListener with handler parameter (another thread) or should I just run without handler?

registerListener(SensorEventListener listener, Sensor sensor, int rate, Handler handler)

registerListener(SensorEventListener listener, Sensor sensor, int rate).

Upvotes: 0

Views: 641

Answers (1)

alex
alex

Reputation: 11400

I don't think the Service should implement SensorEventListener. You should rather create a new Thread inside a Service (since it is run in the UI Thread by default), a there yet another class designed for sensors data collection only. And have in mind that acceleration data is not being collected after the screen turns off. The easiest way around it is to add a WakeLock.

Upvotes: 1

Related Questions