我有一个名为CameraPreview
的简单类,这是代码:
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
public CameraPreview(Context context) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
try {
mCamera = Camera.open();
} catch (RuntimeException e) {}
try {
SurfaceHolder someHolder = holder;
mCamera.setPreviewDisplay(someHolder);
mCamera.startPreview();
} catch (IOException e) {
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (mHolder.getSurface() == null)
return;
try {
mCamera.stopPreview();
} catch (Exception e){}
mCamera.setDisplayOrientation(90);
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
} catch (Exception e){}
}
}
很明显,当应用程序在屏幕上显示CameraPreview
时,它会更快耗电,我的问题是,如果我将此视图设置为View.GONE
,电池会发生什么?< / p>
答案 0 :(得分:0)
根据this SO answer设置,SurfaceView可见性为GONE
将调用surfaceDestroyed
方法。
因此,由于您正在停止相机,因此您不会消耗用户的电池。