Вопрос

I have been developing an application which needs to perform accelerometer calibration in several steps.

What I have done, is create a SensorEventListener that gets a certain amount of readings, and after that amount is reached, I call 'sensorManager().unregisterListener(eventListener)'.

However, I think this line is not unregistering the listener, since immediately afterwards, the same line is called, as a result of continuing to run.

Question: am I doing things properly this way, or should condition my handler so that after reaching this condition it doesn't allow itself to run (using if's)?

Это было полезно?

Решение

If your SensorEventListener only gets called once after you've unregistered it then this behaviour is probably due to a race condition, due to the multi-threaded nature of Android. So if you want to shut off processing the readings, then (as you suggest) you should set a boolean variable and test it with if statements to ensure no further processing once you've reached your limit.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top