android: I get no stacktrace, phone just hangs

廉价感情. 提交于 2019-11-27 20:15:10

I finally (after hours, almost days of debugging) solved this, by removing the preview view and re-instantiating it:

    @Override
    protected void onResume() {
        super.onResume();
        mSurfaceViewContainer.removeAllViews();
        mSurfaceView = new SurfaceView(mSurfaceViewContainer.getContext());
        mSurfaceViewContainer.addView(mSurfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        SurfaceHolder previewHolder = mSurfaceView.getHolder();
        previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        previewHolder.addCallback(mSurfaceHolderCallback);
    }

There is an IOException thrown (Could not find method java.io.IOException.<init>), however the IOException constructor used was introduced in API level 9, so it doesn't exist on the Galaxy S and it shows a strange log instead.

About your problem, I would suggest trying to call lock() before release() :

camera.stopPreview();
camera.lock();
camera.release();
this.camera = null;

I don't know if this will work but in this source code, I found a comment which says :

// If we don't lock the camera, release() will fail.
camera.lock();
camera.release();

It seems clearly related.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!