Can't Register More Than One Sensor In Android Service
I have a service which is called from an Activity. This Service Registers all Sensors and Registers Listener against them. EDIT: I have removed the two lines in onSensorChange() **
Solution 1:
Your OnSensorChanged event is setting the sensorManager to Null so as soon as a sensor is fired no more can be set.
EDIT
If you want each sensor to use a different listener, use something like this instead of implementing the methods on your activity:
privatevoidSetupSensors() {
sensorManager.registerListener(MagneticListener, sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_NORMAL);
}
privateSensorEventListenerMagneticListener=newSensorEventListener() {
@OverridepublicvoidonSensorChanged(SensorEvent sensorEvent) {
// Code here
}
@OverridepublicvoidonAccuracyChanged(Sensor sensor, int i) {
}
};
Post a Comment for "Can't Register More Than One Sensor In Android Service"