1、错误如图所示:
这个问题是关于相机调用后的释放问题
解决如下:
在activity的 onPause、onDestroy中加入如下代码
@Override
protected void onPause() {
super.onPause();
releaseCamera(); // release the camera immediately on pause event
}
private void releaseCamera() {
if (mCamera != null){
mCamera.setPreviewCallback(null);
mPreview.getHolder().removeCallback(mPreview);
mCamera.stopPreview();
mCamera.release(); // release the camera for other applications
mCamera = null;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
releaseCameraAndPreview();
}
private void releaseCameraAndPreview() {
if (mCamera != null) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
if(mPreview != null){
mPreview.destroyDrawingCache();
}
}