문제

I'm trying to log sensor measurements to the device memory. For this, I register the same SensorEventListener for many sensors, and later separate them using a switch, based on the type.

E.g.

int type = sensor.getType();

switch (type) {
    case Sensor.TYPE_ACCELEROMETER:
    // log accelerometer data
    break;

case Sensor.TYPE_GYROSCOPE:
    // Log gyroscope data
    break;

...

My question is, what is the most efficient (less battery power consuming) way, having in mind that I registered the listener with SENSOR_DELAY_FASTEST ? Having one listener for every sensor or having one listener and separating the sensors with a switch?

Thank you very much in advance

Minos

도움이 되었습니까?

해결책

A android application should use one SensorEventListener per Sensor as every SensorEventListener creates its own FIFO buffer to process the SensorEvent. The consumption level of the current through the chip is related with the delay provided to the sensor irrespective of the SensorEventListener it is attached with.

If multiple sensors are used with one SensorEventListener than some events may get lost, due to buffer overflow, when the sensors are used at SENSOR_DELAY_FASTEST.

So,For best results and to ensure that no event is lost:

  • Use one SensorEventListener for one sensor.

    For increase in efficiency:

  • when pausing the application, un-register all the sensor registered ,if they are not required, so they do not get events from the chip even after the application is closed.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top