SurfaceView带摄像头preVIEW不被破坏 [英] SurfaceView with camera preview is not destroyed

查看:179
本文介绍了SurfaceView带摄像头preVIEW不被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选项卡的活动有2个选项卡(活动)。每个标签都有一个3D Open GL的场景画上有摄像头preVIEW一个SurfaceView之上。

I have a Tab Activity with 2 tabs (activities). Each tab has a 3d Open GL scene drawn on top of a SurfaceView with camera preview.

不过,这取决于设备的方向,标签被切换。

Yet, depending on device orientation, tabs are being switched.

的问题是,在其他活动开始时,它调用camera.open(),它产生例外,说相机服务不可用。

The problem is that when the other activity starts, it calls camera.open(), which generates exception, saying that camera service is unavailable.

在实际上,问题是,当活动暂停该摄像机不停止,换句话说onSurfaceDestroyed()不要求的SurfaceView。 我试图阻止摄像机时的onPause()的活动被称为,但得到了同样的错误还在。

In fact, the problem is that camera is not stopped when activity is paused, in other words onSurfaceDestroyed() is not called for the SurfaceView. I tried to stop camera when onPause() for activities is called, but get the same error still.

没有人有标签的活动同样的问题?任何想法如何使surfaceview被摧毁?

Anyone had same issues with tabbed activities? Any idea how to make surfaceview get destroyed?

推荐答案

看起来,这个问题很受欢迎,所以我加入这里的解决方案更多的时间。

It looks like this question is quite popular, so I'm adding the solution here one more time.

的根本原因是,surfaceDestroyed从来没有所谓的SurfaceView,当应用程序被暂停。

The root cause was that surfaceDestroyed was never called for SurfaceView when app was paused.

所以,我创建了一个的FrameLayout它包含了所有的子视图。 将其设置为内容视图。 然而,通过简单地调用setVisibility(View.GONE)中的onPause()和View.Visible在onResume()停止摄像。这将导致毁灭SurfaceView的。

So I've created a framelayout which contains all the child views. Set it as content view. Yet stop camera by simply calling setVisibility(View.GONE) in onPause() and View.Visible in onResume(). This will lead to destruction of SurfaceView.

这篇关于SurfaceView带摄像头preVIEW不被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆