Alex Rivera | Logout

Release Android Camera without restart?

Asked 2011-11-15T06:20:49.843
17

I'm currently trying to get the camera working in my app and I'm having issues with the whole camera.release() thing; I'm doing pretty complicated stuff and there's no clear cut way to simply call camera.release() so I have to keep trying new ways, but every time I get it wrong my app crashes (as expected), leaving the camera not released. So, in order to be able to test my app again, I need to restart my phone in order to refresh the camera.

Is there any way to release the camera through the terminal or DDMS, or is the only way to release it by restarting my phone? It's getting pretty old, especially when a tiny mistake leads to wasted time waiting for my phone to restart.

Thanks!

Edit
Report

1 Answer

4

I'm not sure if there's a way to reset the camera through terminal or DDMS, but I've had a lot of success by putting my call to Camera.release() in my Activity's onPause() method, so the camera gets released whenever the App goes into the background. Similarly, my Camera initialization all happens in onResume(), so the camera will be opened on first run, then released and re-initialized again as your app moves to and from the background. This technique has completely eliminated the problem that you're describing for me.

If the problem persists for you, also consider wrapping the code that's likely to crash in a try/catch, where you catch any Exception and make the call to release the camera in that catch block. I usually use this technique for errors that can be smoothed over without shutting down the app, however I believe it will work in all cases.

answered 2013-06-24T15:40:24.143

Your Answer