I'm trying to get only 1 event from orientation sensor.
My code is:
@Override
public void onSensorChanged(SensorEvent event) {
Log(event);
unregisterSensor(...);
}
Then in a thread every 1000ms I do:
registerSensor();
Thread.sleep(2000);
The problem is that if I unregister the sensor after at the end of the method (like I've done) then next time (when I re-register the sensor) it will log the same value event catched before (while moving the phone). If I give onSensorChanged the ability to run twice (using a counter), then it detects the right value and logs this value twice.
What's the problem with the method called only once?