I'm using the following code to release camera in onPause. But the line mCamera.release() takes 30 seconds on average to release the camera in Nexus 10 device. I've added logging before and after mCamera.release() and found that the time difference between printing these logs is 30 seconds.
private void releaseCamera() {
if (mCamera != null) {
previewing = false;
mCamera.setPreviewCallback(null);
if(mPreview != null)
mPreview.getHolder().removeCallback(mPreview);
Log.e("QR","Starting to call mCamera.release()");
mCamera.release();
Log.e("QR","Released Camera");
mCamera = null;
}
}
I'm calling mCamera.stopPreview() before calling releaseCamera()
Is there any way by which I can do it asynchrounously? Because it takes just less than a minute to go from the Camerapreview activity to the next activity.
Edit1: We reduced the preview size from the highest(1080x1920) to a middle range (480x800) and everything started working fine. Is the preview size has anything to do with the camera release in HAL?
You can try to release the camera inside a Thread as a workaround for this, though this is not an ideal solution. You can launch your next activity while the release function executes in background
new AsyncTask() {
@Override
protected Object doInBackground(Object... params) {
releaseCamera();
return null;
};
}.execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With