[안드로이드][카메라]java.lang.RuntimeException: cancelAutoFocus failed
카메라 기능을 사용하여 테스트 하는 과정에 오류가 하나 발생하였다. 액티비티 창을 휴대폰의 뒤로 가기 버튼을 사용하면서 발생하였다.
............................
private ZXingScannerView mScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_scanner);
mScannerView = new ZXingScannerView(this);
contentFrame.addView(mScannerView);
// Toogle autofocus:
//mScannerView.setAutoFocus(true);
mScannerView.setResultHandler(this);
// this paramter will make your HUAWEI phone works great!
//mScannerView.setAspectTolerance(0.5f);
mScannerView.startCamera();
}
...................
java.lang.RuntimeException: cancelAutoFocus failed
at android.hardware.Camera.native_cancelAutoFocus(Native Method)
at android.hardware.Camera.cancelAutoFocus(Camera.java:1399)
at me.dm7.barcodescanner.core.CameraPreview.stopCameraPreview(CameraPreview.java:120)
at me.dm7.barcodescanner.core.CameraPreview.surfaceDestroyed(CameraPreview.java:79)
at android.view.SurfaceView.updateSurface(SurfaceView.java:861)
at android.view.SurfaceView.windowStopped(SurfaceView.java:235)
at android.view.ViewRootImpl.setWindowStopped(ViewRootImpl.java:1573)
at android.view.WindowManagerGlobal.setStoppedState(WindowManagerGlobal.java:647)
at android.app.Activity.performStop(Activity.java:8035)
at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:4616)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:4594)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4669)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:233)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
[해결법]
카메라 모듈 사용 후 종료시, 반환해야한다. onBackPressed()메소드를 오버라이드하여 카메라 모듈 사용을 종료 후 finish()를 호출한다.
@Override
public void onBackPressed() {
if(mScannerView!=null)
mScannerView.stopCamera();
mScannerView = null;
finish();
}