// unregister
  @Override
  public void onPause() {
    super.onPause();
    sensorManager.unregisterListener(this);

    // camera
    // Because the Camera object is a shared resource, it's very
    // important to release it when the activity is paused.
    if (mCamera != null) {
      mPreview.setCamera(null);
      mCamera.release();
      mCamera = null;
    }
    // end camera
  }
  // register to listen to sensors
  @Override
  public void onResume() {
    Log.e("onResume", " ");
    super.onResume();

    Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST);

    // sensorManager.registerListener(this, sensor);

    // camera
    // Open the default i.e. the first rear facing camera.
    mCamera = Camera.open();
    mCamera.setDisplayOrientation(90);

    // cameraCurrentlyLocked = defaultCameraId;
    mPreview.setCamera(mCamera);

    // end camera
  }