@Override protected void onResume() { super.onResume(); // Open the default i.e. the first rear facing camera. mCamera = Camera.open(); if (mCamera == null) { // Cancel request if mCamera is null. cancelRequest(); return; } mPreview.setCamera(mCamera); mPreview.showSurfaceView(); mPreviewing = true; }
@Override protected void onPause() { super.onPause(); // 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.cancelAutoFocus(); mCamera.setPreviewCallback(null); mCamera.stopPreview(); mCamera.release(); mPreview.hideSurfaceView(); mPreviewing = false; mCamera = null; } }