문제

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