@Override
  protected void onPause() {
    super.onPause();

    bluetoothTransmitter.closeBluetoothSocket();
    forwardMotionExecutor.setMotion(ForwardMotionExecutor.MOTION_REMOVE_ALL);
    sensorManager.unregisterListener(spacialSensorListener);
  }
  @Override
  protected void onResume() {
    super.onResume();
    if (macAddress != null) {
      bluetoothTransmitter.createBluetoothSocket(Arrays.asList(macAddress));
    }

    forwardMotionExecutor.setMotion(ForwardMotionExecutor.MOTION_DECELERATE);

    if (stepMode) {
      sensorManager.registerListener(
          spacialSensorListener, stepSensor, SensorManager.SENSOR_DELAY_GAME);
    } else {
      sensorManager.registerListener(
          spacialSensorListener, magneticField, SensorManager.SENSOR_DELAY_GAME);
      sensorManager.registerListener(
          spacialSensorListener, gravField, SensorManager.SENSOR_DELAY_GAME);
    }
  }
 @Override
 public void onDirectionChanged(int updatedDirection) {
   Log.d("SENDING", Integer.toString(updatedDirection));
   bluetoothTransmitter.transmitDirection(updatedDirection);
 }
 @Override
 public void onSpeedChanged(int updatedSpeed) {
   bluetoothTransmitter.transmitSpeed(updatedSpeed);
 }