Star Chu
Star Chu

Reputation: 31

Camera doesn't be released sometimes after application re-installed

I'm developing a camera application. Sometimes I tried to re-install the app when it is in foreground. In the installation process, the application will be killed, and the the onPause() won't be invoked, in which I stop the preview and release the camera resource. Under normal circumstances, 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 these log information didn't print out. And I guess it means the camera was not released. So when the app restarted, it throws a runtime exception "failed to connect to camera service" when trying open the camera.

Does anyone have any idea about why the system didn't release the camera when killed it.

Upvotes: 3

Views: 1745

Answers (3)

Nataliia.dev
Nataliia.dev

Reputation: 2972

Did you add permissions to your Manifest file?

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

Upvotes: 1

hepizoj
hepizoj

Reputation: 263

Dont allow users to use the cam when the phone is running out of memory. You don't want your app to get blamed when android kills processes.

Upvotes: 0

TG-9256
TG-9256

Reputation: 3

Maybe try putting your cam.release() in an onDestroy instead of an onPause method? I don't know if it will help but that's. what I would to to see if it fixes it.

Upvotes: 0

Related Questions