Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SurfaceView with camera preview is not destroyed

I have a Tab Activity with 2 tabs (activities). Each tab has a 3d Open GL scene drawn on top of a SurfaceView with camera preview.

Yet, depending on device orientation, tabs are being switched.

The problem is that when the other activity starts, it calls camera.open(), which generates exception, saying that camera service is unavailable.

In fact, the problem is that camera is not stopped when activity is paused, in other words onSurfaceDestroyed() is not called for the SurfaceView. I tried to stop camera when onPause() for activities is called, but get the same error still.

Anyone had same issues with tabbed activities? Any idea how to make surfaceview get destroyed?

like image 655
Kirill Volkov Avatar asked Nov 24 '11 12:11

Kirill Volkov


1 Answers

private SurfaceHolder.Callback mSurfaceHolderListener = new SurfaceHolder.Callback() {

    public void surfaceDestroyed(SurfaceHolder holder) {
        Log.e("TABACT", "surfaceDestroyed()");
        camera.stopPreview();
        camera.setPreviewCallback(null); 
        camera.release();
        camera = null;
    }
like image 65
Kirill Volkov Avatar answered Oct 22 '22 21:10

Kirill Volkov