API 15. 当我在拍照后停止相机并转到主屏幕并重新打开我的应用程序并尝试拍摄另一张照片时,我的应用程序崩溃并出现此错误:
04-20 12:04:38.437: E/AndroidRuntime(5150): FATAL EXCEPTION: Timer-2
04-20 12:04:38.437: E/AndroidRuntime(5150): java.lang.RuntimeException: Method called after release()
04-20 12:04:38.437: E/AndroidRuntime(5150): at android.hardware.Camera.native_takePicture(Native Method)
04-20 12:04:38.437: E/AndroidRuntime(5150): at android.hardware.Camera.takePicture(Camera.java:947)
04-20 12:04:38.437: E/AndroidRuntime(5150): at android.hardware.Camera.takePicture(Camera.java:892)
04-20 12:04:38.437: E/AndroidRuntime(5150): at com.prism.app.PrismActivity$5.run(PrismActivity.java:167)
04-20 12:04:38.437: E/AndroidRuntime(5150): at java.util.Timer$TimerImpl.run(Timer.java:284)
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, now tell the camera where to draw the preview.
if (mCamera == null) {
try {
mCamera = Camera.open();
mCamera.setPreviewDisplay(holder);
mCamera.setDisplayOrientation(90);
mCamera.startPreview();
} catch (IOException e) {
// error setting preview of camera
}
} else {
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// empty. Take care of releasing the Camera preview in your activity.
if (mCamera != null) {
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release(); //need to take care of case when app is not closed completely still need to release
mCamera = null;
}
}