I'm currently using a custom camera, however when I choose to select a image from the gallery and I press back and then continue to take a picture, it crashes on a nullpointer in the mCamera instance.
When I open the gallery I choose to release the camera, this works. After that when I press back, it comes in the activity for result. From there I manually call the method that creates all the instances the camera needs. However when calling the mCamera.open it gives an error, which I catch. But when I want to take a picture it crashes because the mCamera is a null.
What am I doing wrong here? I release the camera so it should be able to get a new one.
Edit:
Release:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 100);
try {
mCamera.release();
Log.e("Camera", "Camera has been released");
} catch (NullPointerException E){
E.printStackTrace();
}
Create:
// Create an instance of Camera
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);