Domanda

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)?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top