Search code examples
androidcamerapreview

How do I stop the camera preview without taking picture in Android


I have set up a FrameLayout to be the preview screen for my camera and it works great.

private void fireUpCamera() {
    mCamera = getCameraInstance();  // Create an instance of Camera
    // Create our Preview view and set it as the content of our activity.
    mPreview = new CameraPreview(this, mCamera);// Create our Preview view.
    FrameLayout preview = (FrameLayout) findViewById(R.id.quest_image);
    preview.addView(mPreview);
}

how do I release this preview and camera in my cancel button without taking the picture?


Solution

  • If you want to remove the mPreview view from the FrameLayout named preview you could simply remove the view from the layout like this:

    preview.removeView(mPreview);