锁屏后摄像头preVIEW冻结 [英] Camera preview freezes after screen lock
问题描述
自定义相机应用程序,我已经写了停止后的屏幕锁定(通过推动锁比唐或等待一两分钟)给予preVIEW。我没有得到一个例外,这使得它很难找到问题。
The custom camera app I've written stops giving the preview after the screen locks (by pushing lock butten or waiting for a couple of minutes). I don't get an exception, which makes it quite difficult to find the problem.
难道Android的屏幕锁定(如果这是正确的说法)暂停/暂停/ ......我的应用程序(活动)?
Does the android screen lock (if that's the correct term) pauses/halts/... my App (activity)?
如果是这样的话,可能的原因是我的onPause / onResume方法呢?抑或是其他原因铁道部可能?
If this were the case, could the cause be my onPause/onResume methods? Or is another cause mor likely?
在此先感谢
推荐答案
我面临同样的问题,并修复它使用以下步骤:
I faced same problem and fixed it using following steps:
-
我创造了我的相机,preVIEW并把它添加到容器的FrameLayout父活动的onResume()。是这样的:
I created my camera preview and added it to the container FrameLayout in onResume() of the parent activity. Something like:
public void onResume{
super.onResume();
mCamera = Camera.open();
if(null != mCamera){
mCamera.setDisplayOrientation(90);
mPreview = new CameraOverlay(getActivity(), mCamera);
frLyParent.addView(mPreview);
}
}
我删除在的onPause视图()。这修复了冻结。
I removed the view in onPause(). This fixes the freeze.
public void onPause(){
super.onPause();
if(null != mCamera){
mCamera.release();
mCamera = null;
}
frLyParent.removeView(mPreview);
mPreview = null;
}
其中CameraOverlay()是其延伸SurfaceView并实现SurfaceHolder.Callback类。请让我知道如果你需要的实现。
where CameraOverlay() is the class which extends SurfaceView and implements SurfaceHolder.Callback. Do let me know if you need that implementation.
这篇关于锁屏后摄像头preVIEW冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!