开发者

Safely executing a function in a not-thread-safe class (Android Camera)

I'm using the callback onPreviewFrame for my application, but it causes problems when I try to exit the activity. Without the callback, clicking back has no issues, but with the callback, clicking back will alert me that a call has been made after release() on the camera object has been executed.

Note: the callback is threaded (I believe this is the default implementation), and continues to try to access the camera object after it's been killed.

How can I safely exit the activity without this callback causing me problems? If you'd like to see code I can p开发者_StackOverflowost some.


This seems kind of ridiculous to me, but perhaps in the onPause() method where one would normally call

mCamera.stopPreview()
mCamera.release()

a callback should be set:

mCamera.stopPreview()
mCamera.setPreviewCallback(null)
mCamera.release()

This assures us that no calls will be made to the camera once the preview has been destroyed. Seems to work..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜