问题
So while developing a custom camera application I've realized on rare occasions and on various devices if the app has to force close, it does not always release the camera resource.
Is there a way to find/detect the process that is holding onto this resource and kill it? Or some other technique? It is rather difficult bug to reproduce (for me anyway), but ultimately the device has to be restarted.
Thanks!
回答1:
From chasing up on all the other posts you have made on this subject, it appears like there is no sure fire way of getting the camera back after a crash without a restart of the device. A pain, to be sure. Best option is not to crash / catch everything that might fault. Which is a pretty rubbish answer, but that's what I'm endeavouring to do now.
Lots and lots of try catch !
回答2:
I suggest you to see the code of google sample apps completely. the link is as follow. https://github.com/googlesamples/android-Camera2Basic As you can see in Camera2BasicFragment, mCameraOpenCloseLock Semaphore used to resolve release resources problems.
来源:https://stackoverflow.com/questions/4799183/android-camera-api-force-close-does-not-release-camera-resource