Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: camera view - app crashes when I don't use a deprecated method
    text
    copied!<p>In my app, I am trying to set up the camera. My class extends SurfaceView and implements the SurfaceHolder.Callback methods.</p> <p>Here is some of my class:</p> <pre><code>public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback{ private SurfaceHolder mHolder; private Camera.Parameters cameraParameters; private Camera camera; public CameraPreview(Context context) { super(context); mHolder = this.getHolder(); mHolder.addCallback(this); // If this is deprecated, why do I still need it? // It says deprecated, but app crashes when removed. mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters parameters = camera.getParameters(); List&lt;Camera.Size&gt; previewSizes = parameters.getSupportedPreviewSizes(); Camera.Size previewSize = previewSizes.get(0); parameters.setPreviewSize(previewSize.width, previewSize.height); camera.setParameters(parameters); try { camera.stopPreview(); camera.setPreviewDisplay(mHolder); camera.startPreview(); } catch (IOException e) { e.printStackTrace(); } } @Override public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); cameraParameters = camera.getParameters(); } @Override public void surfaceDestroyed(SurfaceHolder holder) { camera.stopPreview(); camera.release(); camera = null; } } </code></pre> <p>My question involves the "setType" method in the constructor. The API claims the method is deprecated and ignored. However, if I comment out that one line, the entire application crashes when I call camera.startPreview(). I am trying to figure out why this is. If it's ignored, then it shouldn't matter what I did with that method. It implies that there is something very wrong with this implementation.</p> <p>I am running Android 2.2 software.</p> <p>Any help would be appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload