2
我有一個Android項目的問題,我們的相機預覽停止,但只有在手機已被鎖定然後解鎖後,它也無法拍照,這個問題有我真誠地難倒我一直無法找到在互聯網這個錯誤的任何信息,似乎做什麼都教程/其他堆棧溢出問題狀態:解鎖手機後Android相機預覽停止
@Override
protected void onResume() {
super.onResume();
mPreview.setVisibility(View.VISIBLE);
//Open the default i.e. the first rear facing camera.
mCamera = Camera.open();
try{
mCamera.reconnect();
} catch(Exception ex) {
}
mCamera.startPreview();
cameraCurrentlyLocked = defaultCameraId;
mPreview.setCamera(mCamera);
}
@Override
protected void onPause() {
super.onPause();
mPreview.setVisibility(View.GONE);
//Because the Camera object is a shared resource, it's very
//Important to release it when the activity is paused.
if (mCamera != null) {
mPreview.setCamera(null);
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
}
而且錯誤(在拍攝照片)如下:
02-25 13:26:20.710: W/dalvikvm(17873): threadid=1: thread exiting with
uncaught exception (group=0x41635450)
02-25 13:26:20.710: E/AndroidRuntime(17873): FATAL EXCEPTION: main
02-25 13:26:20.710: E/AndroidRuntime(17873): java.lang.IllegalStateException:
Could not execute method of the activity
02-25 13:26:20.710: E/AndroidRuntime(17873): at
android.view.View$1.onClick(View.java:3671)
02-25 13:26:20.710: E/AndroidRuntime(17873): at
android.view.View.performClick(View.java:4171)
02-25 13:26:20.710: E/AndroidRuntime(17873): at
android.view.View$PerformClick.run(View.java:17195)
02-25 13:26:20.710: E/AndroidRuntime(17873): at
android.os.Handler.handleCallback(Handler.java:643)
02-25 13:26:20.710: E/AndroidRuntime(17873): at
android.os.Handler.dispatchMessage(Handler.java:92)
02-25 13:26:20.710: E/AndroidRuntime(17873): at
android.os.Looper.loop(Looper.java:137)
02-25 13:26:20.710: E/AndroidRuntime(17873): at
android.app.ActivityThread.main(ActivityThread.java:4803)
任何幫助是非常讚賞。
從的FrameLayout刪除預覽中的onPause和的onResume再次添加 – baboo
完美地工作,感謝您的幫助! – Mattiemus
嗯,我應該添加它作爲答案,以便您可以接受它.. :)? – baboo