SensorEventListener does not unregister

I am developing an application that should calibrate the accelerometer in several stages.

What I did was create a SensorEventListener that receives a certain amount of readings, and after reaching this amount I call "sensorManager (). UnregisterListener (eventListener)".

However, I think that this line does not cancel the registration of the listener, since immediately after that the same line is called as a result of continuing work.

Question: Am I doing everything right or should the handler be processed in such a way that after reaching this condition it will not allow it to start (using if's)?

0
source share
1 answer

If your SensorEventListener is called only once after you have not registered it, this behavior is probably due to the state of the race , the raw nature of Android. Therefore, if you want to disable the processing of readings, then (as you believe) you must set a boolean variable and test it using if statements to ensure further processing as soon as you reach your limit.

+1
source

Source: https://habr.com/ru/post/1206949/


All Articles