SensorEventListener doesn't get unregistered with unregisterListener() method
In my case, to solve this problem I needed to correct the context I was using to get SensorManager. I was inside a Service, and I needed to get the SensorManager this way:
SensorManager sensorManager = (SensorManager) getApplicationContext().getSystemService(SENSOR_SERVICE);
So, just certify if you are getting the SensorManager the correct way.
Try setting the manager to null
sensorManager.unregisterListener(sensorEventListener,sensor);sensorManager = null;
and then obtain the manager again when you need it. This should make the thread finish consistently (it did in my case). I haven't found any documentation explaining this behavior but would be interested in hearing about it.