The camera is not released sometimes after reinstalling the app

I am developing a camera app. I have sometimes tried to reinstall the application when it is in the foreground. During the installation process, the app will be killed rather onPause()

than invoked, in which I stop the preview and free the camera resource. Under normal conditions, the system will automatically close and release the camera and I got the following log.

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

      

However, sometimes the log data was not printed. And I think that means that the camera was not released. Therefore, when the application has restarted, a runtime exception " failed to connect to camera service

" is thrown when trying to open the camera .

Does anyone know why the system didn't release the camera when she was killed.

+3


source to share


3 answers


Have you added permissions to the manifest file?



<uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />

      

+1


source


Maybe try putting cam.release () in onDestroy instead of onPause method? I don't know if it helps, but it does. what I'd like to see if he fixes it.



0


source


Do not allow users to use the camera when the computer runs out of memory. You don't want your application to freeze when android kills processes.

0


source







All Articles