Camera Freezes After Sleep
Solution 1:
because the mSurfaceView's oncreated and onchanged can not be call. the most simple way is just set mSurfaceView invisible and visible in the onpause and onresume. in your activity or fragment, add this code:
@OverridepublicvoidonResume() {
super.onResume();
mCamera = Camera.open(0);
mSurfaceView.setVisibility(View.VISIBLE);// this can fix the freeze.
}
@OverridepublicvoidonPause() {
super.onPause();
mSurfaceView.setVisibility(View.GONE);//this to fix freeze.if (mCamera != null) {
mCamera.release();
mCamera = null;
}
}
Solution 2:
Your initCameraPreview()
assumes that mCamera
must be obtained by your app; probably somewhere, e.g. onStop()
you also release the camera (or the system takes care of that for you). But when you put the phone to sleep and then wake up, only onPause()
and onResume()
are called for the current activity.
So, you should make sure you don't try to acquire the camera when it's already yours. One easy way is to add mCamera = null;
immediately after you call to mCamera.close()
; and it case you don't - add this to onStop()
method of your Activity.
Then, in initCameraPreview()
you can simply check
if (mCamera == null) {
mCamera = getCameraInstance();
}
Post a Comment for "Camera Freezes After Sleep"