Yes, you should do that, since the data will still be send to your app and I believe it's always a good programming style to "close" (unregister)
something you "opened" (registered)
. I've written some example methods that demonstrate how to do this:
(Note: This code would have to be placed in the class that implements SensorEventListener, OnTouchListener, OnKeyListener
)
/**
* <b><i>public void useAccelerometer(boolean use)</i></b>
* <br>
* Since: API 1
* <br>
* <br>
* Set if you would like to enable the use of the accelerometer.
*
* @param use
* <br>
* True will enable the use of the accelerometer.
* <br>
* False will disable the use of the accelerometer.
*
*/
public void useAccelerometer(boolean use) {
if(use == true) {
manager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Accelerometer enabled");
}
}
else {
manager.unregisterListener(this, accelerometer);
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Accelerometer disabled");
}
}
}
/**
* <b><i>public void useTouchscreen(boolean use)</i></b>
* <br>
* Since: API 1
* <br>
* <br>
* Set if you would like to enable the use of the touch screen.
*
* @param use
* <br>
* True will enable the use of the touch screen.
* <br>
* False will disable the use of the touch screen.
*
*/
public void useTouchscreen(boolean use) {
if(use == true) {
view.setOnTouchListener(this);
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Touchscreen enabled");
}
}
else {
view.setOnTouchListener(null);
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Touchscreen disabled");
}
}
}
/**
* <b><i>public void useKeyboard(boolean use)</i></b>
* <br>
* Since: API 1
* <br>
* <br>
* Set if you would like to enable the use of the keyboard.
*
* @param use
* <br>
* True will enable the use of the keyboard.
* <br>
* False will disable the use of the keyboard.
*
*/
public void useKeyboard(boolean use) {
if(use == true) {
view.setOnKeyListener(this);
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Keyboard enabled");
}
}
else {
view.setOnKeyListener(null);
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Keyboard disabled");
}
}
}