我暂停相机应用后手机崩溃,然后切换回来拍照.这只发生在我的三星Galaxy S上,在我的Huwai设备上它完全有效.我找到了导致错误的代码行.不幸的是,这些行很有用,所以我不能剥离它们:
public void surfaceDestroyed(SurfaceHolder holder) { // <14>
Log.d(TAG,"surfaceDestroyed()");
if(this.camera != null){
camera.stopPreview();
// the next two lines lead to the error after switching back to the app and taking a picure
camera.release();
this.camera = null;
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是我没有得到堆栈跟踪.我得到的只是:
12-17 12:45:01.609: ERROR/SecCamera(10857): cancelAutofocus() end, 0, 2
12-17 12:45:01.613: ERROR/SecCamera(10857): stopPreview()
12-17 12:45:01.613: ERROR/SecCamera(10857): fimc_v4l2_streamoff()
12-17 12:45:01.644: ERROR/CameraHardwareSec(10857): stopPreview() end
12-17 12:45:01.644: INFO/ShotSingle(10857): ShotSingle::takePicture end
12-17 12:45:01.644: DEBUG/SecCamera(10857): passed fmt = 1498831189 found pixel format[3]: YUV 4:2:2 packed, CbYCrY
12-17 …Run Code Online (Sandbox Code Playgroud) 我在这里有我的Activity课程:
public class CameraActivity extends Activity {
private Camera mCamera;
private CameraPreview mPreview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// startCamera();
}
public void startCamera() {
setContentView(R.layout.camera_view);
mCamera = getCameraInstance();// Open Camera
mPreview = new CameraPreview(this,mCamera);// Goto Another Class
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.setLayoutParams(new FrameLayout.LayoutParams(400,400));
//Declare Frame in which camera will be opened
preview.addView(mPreview); // show this class into frame
}
protected void onResume() {
super.onResume();
Log.d("Print","resume()");
startCamera();
}
public static Camera getCameraInstance() {
Camera c = null;
try …Run Code Online (Sandbox Code Playgroud)