2
多個傳感器我註冊了3個傳感器到我的傳感器管理器:如何註銷的Android
if(sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) !=null){
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorManager.registerListener(this,accelerometer,SensorManager.SENSOR_DELAY_NORMAL);
}
if(sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) !=null){
gyroscope = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
sensorManager.registerListener(this,gyroscope,SensorManager.SENSOR_DELAY_NORMAL);
}
if(sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) !=null){
magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
sensorManager.registerListener(this,magnetometer,SensorManager.SENSOR_DELAY_NORMAL);
}
和我的onResume方法:
@Override
protected void onResume() {
super.onResume();
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(this, gyroscope, SensorManager.SENSOR_DELAY_NORMAL);
}
所以當我註銷,傳感器管理,我應該註銷的3倍,還是一次?目前我使用這個:
@Override
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(this);
}