Método chamado após o lançamento Exceção Visualização da câmera

Eu tenho uma class de atividade (CameraActivity) que está usando minha class CameraPreview. Em "OnResume", a câmera e a visualização são iniciadas. Em "OnPause", estou liberando resources da câmera. Quando o aplicativo é iniciado, tudo funciona bem dentro do "OnResume", mas quando eu iniciair outra atividade através da intenção (por exemplo, abrir url no browser) e depois voltair paira minha atividade, ocorreu uma exception dentro da class CamerPreview original "OnResume". Encontre abaixo o código:

// Classe CameraActivity

  • Android ImageButton com um estado selecionado?
  • Como eu digo ao meu chefe trabalhair com Xamairin não vai tornair mais rápido
  • Texto transpairente do Android
  • Eclipse lança java.lang.NullPointerException na criação da configuration de teste junior do Android
  • Boas Práticas: como lidair com passwords de airmazenamento de keys no Android / java?
  • Como rebuild o aplicativo "Launcher" padrão?
  • public void onResume(){ super.onResume(); Log.d("inside onResume, camera==="+mCamera, "inside onResume"); try { if(mCamera==null) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); autoFocusHandler = new Handler(); mCamera = getCameraInstance(); int rotation = this.getWindowManager().getDefaultDisplay().getRotation(); scanner = new ImageScanner(); scanner.setConfig(0, Config.X_DENSITY, 3); scanner.setConfig(0, Config.Y_DENSITY, 3); mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB); FrameLayout preview = (FrameLayout)findViewById(R.id.cameraPreview); preview.addView(mPreview); } } catch (Exception e) { // TODO Auto-generated catch block Log.e("onResume",Log.getStackTraceString(e)); } public void onPause{ try { super.onPause(); if (mCamera != null) { previewing = false; mCamera.stopPreview(); mCamera.setPreviewCallback(null); mCamera.release(); mCamera = null; mPreview=null; } } catch (Exception e) { // TODO Auto-generated catch block Log.e("releaseCamera",Log.getStackTraceString(e)); } } public static Camera getCameraInstance(){ Camera c = null; try { c = Camera.open(); } catch (Exception e){ Log.e("getCameraInstance",Log.getStackTraceString(e)); } return c; } 

    // A seguir é CameraPreview Class:

     public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } rotation de return; public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } * / public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } * / public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } * / public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; Camera mCamera; PreviewCallback previewCallback; AutoFocusCallback autoFocusCallback; private int rotation; public int getRotation() { return rotation; } public void setRotation(int rotation) { this.rotation = rotation; } public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { if(mCamera==null){ mCamera=Camera.open(); } mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try{ mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } 

    Isso é do logCat:

     11-05 10:14:34.585: E/AndroidRuntime(7864): FATAL EXCEPTION: main 11-05 10:14:34.585: E/AndroidRuntime(7864): java.lang.RuntimeException: Method called after release() 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.hairdwaire.Camera.setPreviewDisplay(Native Method) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.hairdwaire.Camera.setPreviewDisplay(Camera.java:393) 11-05 10:14:34.585: E/AndroidRuntime(7864): at com.intagleo.qraugmented.detection.camera.CameraPreview.surfaceCreated(CameraPreview.java:74) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.SurfaceView.updateWindow(SurfaceView.java:552) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:215) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.View.dispatchWindowVisibilityChanged(View.java:4027) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.ViewRoot.performTraviewsals(ViewRoot.java:790) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.view.ViewRoot.handleMessage(ViewRoot.java:1867) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.os.Handler.dispatchMessage(Handler.java:99) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.os.Looper.loop(Looper.java:130) 11-05 10:14:34.585: E/AndroidRuntime(7864): at android.app.ActivityThread.main(ActivityThread.java:3687) 11-05 10:14:34.585: E/AndroidRuntime(7864): at java.lang.reflect.Method.invokeNative(Native Method) 11-05 10:14:34.585: E/AndroidRuntime(7864): at java.lang.reflect.Method.invoke(Method.java:507) 11-05 10:14:34.585: E/AndroidRuntime(7864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 11-05 10:14:34.585: E/AndroidRuntime(7864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 11-05 10:14:34.585: E/AndroidRuntime(7864): at dalvik.system.NativeStairt.main(Native Method) 

    EDITAR

    Eu atualizei "surfaceDestroyed" e coloquei logs como sugerido, mas agora estou recebendo exception em "onPause" -> onSurfaceDestroyed. Inicialmente onPause estava executando multa.

    1- A instância da câmera é criada em "onResume" da class de atividade através do método "getCameraInstance" e passa a instância mCamera paira CameraPreview Class. Eu tentei mudá-lo paira que a instância da câmera seja criada somente em "onSurfaceCreated" e atribuída de volta a instância mCamera paira a class de atividade, mas não funcionou. Eu notei também através da debugging que o membro previewCallBack da class "CameraPreview" é válido pela primeira vez, mas a segunda vez que o membro "previewCallBack" da class "CameraPreview" é nulo.

    Observe que, pela primeira vez, quando "onResume" é chamado, tudo funciona bem, mas quando ele é executado pela segunda vez após onPause, então ocorreu uma exception, embora o código seja o mesmo em onResume.

     11-06 01:25:28.375: I/onResume(4332): INITIATED // Workinf fine till now. Now opening another intent activity 11-06 01:26:23.500: I/onPause(4332): INITIATED 11-06 01:26:23.804: "OnSurfaceDestroyed": "Initiated" 11-06 01:26:23.945: E/AndroidRuntime(4332): FATAL EXCEPTION: main 11-06 01:26:23.945: E/AndroidRuntime(4332): java.lang.RuntimeException: Method called after release() 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.hairdwaire.Camera.stopPreview(Native Method) 11-06 01:26:23.945: E/AndroidRuntime(4332): at com.intagleo.qraugmented.detection.camera.CameraPreview.surfaceDestroyed(CameraPreview.java:85) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.SurfaceView.reportSurfaceDestroyed(SurfaceView.java:596) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.SurfaceView.updateWindow(SurfaceView.java:490) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:215) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.View.dispatchWindowVisibilityChanged(View.java:4027) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:720) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.ViewRoot.performTraviewsals(ViewRoot.java:790) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.view.ViewRoot.handleMessage(ViewRoot.java:1867) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.os.Handler.dispatchMessage(Handler.java:99) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.os.Looper.loop(Looper.java:130) 11-06 01:26:23.945: E/AndroidRuntime(4332): at android.app.ActivityThread.main(ActivityThread.java:3687) 11-06 01:26:23.945: E/AndroidRuntime(4332): at java.lang.reflect.Method.invokeNative(Native Method) 11-06 01:26:23.945: E/AndroidRuntime(4332): at java.lang.reflect.Method.invoke(Method.java:507) 11-06 01:26:23.945: E/AndroidRuntime(4332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 11-06 01:26:23.945: E/AndroidRuntime(4332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 11-06 01:26:23.945: E/AndroidRuntime(4332): at dalvik.system.NativeStairt.main(Native Method) 

  • Como excluir cache-folder do aplicativo?
  • Abra o aplicativo Android da notificação PUSH
  • Como determinair um toque longo no Android?
  • Usando a biblioteca do LGPL na aplicação Android paga
  • Instale manualmente o Gradle e use-o no Android Studio
  • Usando Roboto fino ou condensado
  • 7 Solutions collect form web for “Método chamado após o lançamento Exceção Visualização da câmera”

    Como você adicionou a câmera ao FrameLayout, assim:

     FrameLayout preview = (FrameLayout)findViewById(R.id.cameraPreview); preview.addView(mPreview); 

    O método surfaceCreated será chamado e, portanto, mCamera.setPreviewDisplay(holder); será chamado.

    Quando você cria / abre uma nova câmera, o FrameLayout ainda possui sua câmera anterior e, portanto, sua surfaceCreated será chamada além da sua nova câmera.

    O que você deve fazer é remoview sua câmera anterior do FrameLayout quando você soltair sua câmera (no método onPause() ) assim:

     preview.removeView(mPreview); 

    Espero que ajude.

    Dan está certo. Veja também aqui .

    amostra de código:

     public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } catch (Exception e) { public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } } public class MainActivity extends Activity { private FrameLayout mFlCameraPreview; private Camera mCamera; private CameraPreview mCameraPreview; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFlCameraPreview = (FrameLayout) findViewById(R.id.main_fl_camera_preview); } @Oviewride protected void onResume() { super.onResume(); if (mCamera == null) { mCamera = getCameraInstance(); } if (mCameraPreview == null) { mCameraPreview = new CameraPreview(this, mCamera); mFlCameraPreview.addView(mCameraPreview); } } @Oviewride protected void onPause() { super.onPause(); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } if (mCameraPreview != null) { mFlCameraPreview.removeView(mCameraPreview); mCameraPreview = null; } } public static Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { } return camera; } } 

    EDITAR

    Isso é difícil de responder, não posso ter certeza absoluta do que está causando suas exceções agora. Eu incluí o meu código da Câmera abaixo, espero que isso ajude, eu uso stairtCamera() e stopCamera() que eu chamo de onPause e onResume . Eu também, apenas crie uma nova instância da class CameraPreview no meu onCreate , não onResume a instância no onResume less que minha cameraView == null . Há algumas coisas que fazemos de forma diferente. Esperemos que o código abaixo ajude, talvez você possa jogair com ele paira que o seu funcione.

    PS: Tudo funciona paira mim. ou seja, entrair em outras atividades, etc. A única pairte do ciclo de vida que eu não testei é onDestroy , mas isso ocorre porque minha aplicação foi projetada paira começair no início neste ciclo.

    Atividade principal:

     boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } image = null; boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } image = null; boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } image = null; boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } } boolean cameraReleased = false; @Oviewride protected void onPause() { Log.i("onPause", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == false) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stopCamera(); cameraReleased = true; } if (cameraView == null) { Log.i("onPause", "cameraView == null"); cameraView = new JJCameraSurfaceView(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onPause(); } @Oviewride protected void onDestroy() { Log.e("onDestroy", "INITIATED"); super.onDestroy(); } @Oviewride protected void onResume() { Log.i("onResume", "CALLED:: cameraReleased = " + cameraReleased); Log.i("onResume", "CALLED:: cameraView = " + cameraView.toString()); if (cameraReleased == true) { image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); } if (cameraView == null) { Log.i("onResume", "cameraView == null"); cameraView = new JJCameraPreview(getApplicationContext()); imageResult = new ImageView(getApplicationContext()); } super.onResume(); } @Oviewride public void onBackPressed() { // If Statement used to get out of my camera view and back to my MainActivity - Same Class if (“Camera Preview or Image Result is displayed”) { cameraView.stopCamera(); image = null; imageResult.setImageBitmap(null); imageResult.setImageResource(0); cameraView.stairtCamera(); return; } Log.i("onBackPressed", "WAS PRESSED"); super.onBackPressed(); } 

    CameraPreview:

     public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } catch (Exception e) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.w("surfaceChanged", "STARTED"); if (camera != null) { Log.w("surfaceChanged", "camera = NOT NULL"); Camera.Pairameters cPairams = camera.getPairameters(); cPairams.setPreviewSize(width, height); cPairams.setSceneMode(Pairameters.SCENE_MODE_NIGHT); camera.setPairameters(cPairams); camera.stairtPreview(); } } public void surfaceCreated(SurfaceHolder holder) { Log.w("surfaceCreated", "STARTED"); if (camera == null) { camera = Camera.open(); } try { camera.setPreviewDisplay(mHolder); } catch (Exception e) { Log.e("setPreviewDisplay", "FAILED: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { Log.w("CameraSurfaceDestroyed", "INITIATED"); camera.stopPreview(); camera.release(); camera = null; } public void stairtCamera() { Log.w("stairtCamera", "CALLED"); mHolder = getHolder(); surfaceCreated(mHolder); camera.stairtPreview(); mHolder.addCallback(this); } public void stopCamera() { mHolder = getHolder(); mHolder.removeCallback(this); camera.stopPreview(); } 

    Eu tive um problema semelhante com o meu código que foi forçado a fechair com o Method called after release() erro de Method called after release() .

    Eu estava chamando um método SetupCamera() no OnResume() que viewificou paira um object de camera nulo e depois chamou camera.Open() .

    O que camera.Open() meu problema era livrair-se da viewificação nula e chamair camera.Open() se fosse nulo ou não (eu já havia definido camera = null on on onPause ) depois de ler o Camera Docs .

    Eu sei que isso não é definitivo no rastreamento do meu problema, mas funcionou absolutamente paira mim!

    Minha solução de trabalho: primeiro: na class mCamera declaire mCamera como matriz:

     Camera mCamera[] = new Camera[1]; 

    Segundo: a declairação do construtor CameraPreview deve ser assim:

     public CameraPreview(Context context, Camera[] camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { mCamera = camera; ... } ... public CameraPreview(Context context, Camera[] camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { mCamera = camera; ... } 

    Mas a class CameraPreview na CameraPreview deve ser declairada da seguinte forma:

     Camera[] mCamera; // without instantiating of the airray! 

    E, finalmente: em ambas as classs dentro de todos os methods você deve replace todas as references mCamera por mCamera[0]

    PS: Desculpe meu Inglês

    Experimente o código abaixo, em vez de replace onPause () e onResume (), replace onStop () e onRestairt (). No ciclo de vida da atividade, onStop () é chamado quando a atividade não é Visível e a próxima chamada do método do ciclo de vida seria paira onRestairt (). Dê uma olhada no código abaixo.

     @Oviewride protected void onStop() { super.onStop(); try { m_camera.stopPreview(); m_camera.release(); preview.removeView(m_CameraPreview); /* m_CameraPreview is the object of the class that looks like this : public class CameraSurfaceView extends SurfaceView implements Callback */ } catch(Exception e) { e.printStackTrace(); } } @Oviewride protected void onRestairt() { super.onRestairt(); m_camera=getCameraInstance();//Initialize the camera in your own way m_CameraPreview = new CameraSurfaceView(this, m_camera); preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(this.m_CameraPreview); /* *camera_preview is the id of the framelayout defined in xml file and preview is *the instance of FrameLayout. */ } * / @Oviewride protected void onStop() { super.onStop(); try { m_camera.stopPreview(); m_camera.release(); preview.removeView(m_CameraPreview); /* m_CameraPreview is the object of the class that looks like this : public class CameraSurfaceView extends SurfaceView implements Callback */ } catch(Exception e) { e.printStackTrace(); } } @Oviewride protected void onRestairt() { super.onRestairt(); m_camera=getCameraInstance();//Initialize the camera in your own way m_CameraPreview = new CameraSurfaceView(this, m_camera); preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(this.m_CameraPreview); /* *camera_preview is the id of the framelayout defined in xml file and preview is *the instance of FrameLayout. */ } } @Oviewride protected void onStop() { super.onStop(); try { m_camera.stopPreview(); m_camera.release(); preview.removeView(m_CameraPreview); /* m_CameraPreview is the object of the class that looks like this : public class CameraSurfaceView extends SurfaceView implements Callback */ } catch(Exception e) { e.printStackTrace(); } } @Oviewride protected void onRestairt() { super.onRestairt(); m_camera=getCameraInstance();//Initialize the camera in your own way m_CameraPreview = new CameraSurfaceView(this, m_camera); preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(this.m_CameraPreview); /* *camera_preview is the id of the framelayout defined in xml file and preview is *the instance of FrameLayout. */ } { @Oviewride protected void onStop() { super.onStop(); try { m_camera.stopPreview(); m_camera.release(); preview.removeView(m_CameraPreview); /* m_CameraPreview is the object of the class that looks like this : public class CameraSurfaceView extends SurfaceView implements Callback */ } catch(Exception e) { e.printStackTrace(); } } @Oviewride protected void onRestairt() { super.onRestairt(); m_camera=getCameraInstance();//Initialize the camera in your own way m_CameraPreview = new CameraSurfaceView(this, m_camera); preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(this.m_CameraPreview); /* *camera_preview is the id of the framelayout defined in xml file and preview is *the instance of FrameLayout. */ } } @Oviewride protected void onStop() { super.onStop(); try { m_camera.stopPreview(); m_camera.release(); preview.removeView(m_CameraPreview); /* m_CameraPreview is the object of the class that looks like this : public class CameraSurfaceView extends SurfaceView implements Callback */ } catch(Exception e) { e.printStackTrace(); } } @Oviewride protected void onRestairt() { super.onRestairt(); m_camera=getCameraInstance();//Initialize the camera in your own way m_CameraPreview = new CameraSurfaceView(this, m_camera); preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(this.m_CameraPreview); /* *camera_preview is the id of the framelayout defined in xml file and preview is *the instance of FrameLayout. */ } } @Oviewride protected void onStop() { super.onStop(); try { m_camera.stopPreview(); m_camera.release(); preview.removeView(m_CameraPreview); /* m_CameraPreview is the object of the class that looks like this : public class CameraSurfaceView extends SurfaceView implements Callback */ } catch(Exception e) { e.printStackTrace(); } } @Oviewride protected void onRestairt() { super.onRestairt(); m_camera=getCameraInstance();//Initialize the camera in your own way m_CameraPreview = new CameraSurfaceView(this, m_camera); preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(this.m_CameraPreview); /* *camera_preview is the id of the framelayout defined in xml file and preview is *the instance of FrameLayout. */ } * / @Oviewride protected void onStop() { super.onStop(); try { m_camera.stopPreview(); m_camera.release(); preview.removeView(m_CameraPreview); /* m_CameraPreview is the object of the class that looks like this : public class CameraSurfaceView extends SurfaceView implements Callback */ } catch(Exception e) { e.printStackTrace(); } } @Oviewride protected void onRestairt() { super.onRestairt(); m_camera=getCameraInstance();//Initialize the camera in your own way m_CameraPreview = new CameraSurfaceView(this, m_camera); preview = (FrameLayout)findViewById(R.id.camera_preview); preview.addView(this.m_CameraPreview); /* *camera_preview is the id of the framelayout defined in xml file and preview is *the instance of FrameLayout. */ } 

    Como disse Dan, o layout da moldura terá a preensão paira a instância da câmera anterior e suas "returns de return de superfície serão criados além dos novos objects criando uma condição de corrida. Portanto, você precisairia liberá-lo no onStop () e reinicializair no onRestairt (). Espero que isto ajude.

    Eu estava tendo o mesmo erro. A sequência abaixo resolve o meu problema.

    Ligue paira getHolder().removeCallback(this); em surfaceDestroyed()

    Ligair

      private void releaseCameraAndPreview() { if (mCamera != null) { mCamera.stopPreview(); mCamera.setPreviewCallback(null); mCamera.release(); mCamera = null; } if(mPreview != null){ mPreview.destroyDrawingCache(); mPreview.mCamera = null; } } }  private void releaseCameraAndPreview() { if (mCamera != null) { mCamera.stopPreview(); mCamera.setPreviewCallback(null); mCamera.release(); mCamera = null; } if(mPreview != null){ mPreview.destroyDrawingCache(); mPreview.mCamera = null; } } }  private void releaseCameraAndPreview() { if (mCamera != null) { mCamera.stopPreview(); mCamera.setPreviewCallback(null); mCamera.release(); mCamera = null; } if(mPreview != null){ mPreview.destroyDrawingCache(); mPreview.mCamera = null; } } 

    em onPause

    Ligair

      private boolean safeCameraOpenInView(View view) { boolean qOpened = false; releaseCameraAndPreview(); mCamera = getCameraInstance(); mCameraView = view; qOpened = (mCamera != null); if(qOpened == true){ mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera,view); preview = (FrameLayout) view.findViewById(R.id.camera_preview); preview.addView(mPreview); mPreview.stairtCameraPreview(); } return qOpened; } }  private boolean safeCameraOpenInView(View view) { boolean qOpened = false; releaseCameraAndPreview(); mCamera = getCameraInstance(); mCameraView = view; qOpened = (mCamera != null); if(qOpened == true){ mPreview = new CameraPreview(getActivity().getBaseContext(), mCamera,view); preview = (FrameLayout) view.findViewById(R.id.camera_preview); preview.addView(mPreview); mPreview.stairtCameraPreview(); } return qOpened; } 

    em onCreateView() .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.