我正在开发一个相机应用程序。有时当应用程序在前台时,我尝试重新安装该应用程序。在安装过程中,应用程序将被终止,并且不会调用 onPause()
方法,在此方法中我停止预览并释放相机资源。在正常情况下,系统会自动关闭并释放相机资源,并显示以下日志。
03-14 15:48:36.316: E/CameraHardwareSec(83): Could not dequeue gralloc buffer!
03-14 15:48:36.316: I/CameraHardwareSec(83): int android::CameraHardwareSec::previewThreadWrapper(): calling mSecCamera->stopPreview() and waiting
03-14 15:48:36.363: I/CameraHardwareSec(83): int android::CameraHardwareSec::previewThreadWrapper(): return from wait
03-14 15:48:36.363: I/CameraHardwareSec(83): int android::CameraHardwareSec::previewThreadWrapper(): exiting
03-14 15:48:36.363: W/SecCamera(83): int android::SecCamera::stopPreview(): doing nothing because m_flag_camera_start is zero
03-14 15:48:36.363: W/SecCamera(83): int android::SecCamera::stopRecord(): doing nothing because m_flag_record_start is zero
03-14 15:48:36.363: I/SecCamera(83): DeinitCamera: m_cam_fd(29)
03-14 15:48:36.371: I/SecCamera(83): DeinitCamera: m_cam_fd2(30)
03-14 15:48:36.386: E/CameraHardwareSec(83): preview window is NULL!
03-14 15:48:36.386: I/CameraService(83): Destroying camera 0
03-14 15:48:36.386: I/CameraHardwareSec(83): int android::HAL_camera_device_close(hw_device_t*)
03-14 15:48:36.386: I/SecCamera(83): DeinitCamera : already deinitialized
03-14 15:48:36.390: W/AudioFlinger(83): session id 89 not found for pid 83
03-14 15:48:36.394: W/AudioFlinger(83): session id 90 not found for pid 83
然而有时这些日志信息并没有输出,我猜测这意味着相机没有被释放。因此,当应用程序重新启动时,尝试打开相机时会抛出一个运行时异常"failed to connect to camera service
"。
有人知道为什么在关闭相机后系统没有释放相机吗?