SurfaceView with camera preview is not destroyed

六月ゝ 毕业季﹏ 提交于 2019-12-04 09:00:30

It looks like this question is quite popular, so I'm adding the solution here one more time.

The root cause was that surfaceDestroyed was never called for SurfaceView when app was paused.

So I've created a framelayout which contains all the child views. Set it as content view. Yet stop camera by simply calling setVisibility(View.GONE) in onPause() and View.Visible in onResume(). This will lead to destruction of SurfaceView.

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;
    }

this is OK for me:

 public void surfaceDestroyed(SurfaceHolder holder) {
        Log.e("TABACT", "surfaceDestroyed()");
        camera.stopPreview();
        camera.setPreviewCallback(null); 
        camera.release();
        camera = null;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!