OGeek|极客世界-中国程序员成长平台

标题: android - GLSurfaceView 渲染器,如何强制重新创建表面? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-9 07:30
标题: android - GLSurfaceView 渲染器,如何强制重新创建表面?

我有一个 GLSurfaceView 渲染器,方法 onSurfaceCreated 只调用一次(基本上只在创建或重新创建 Activity 时)。

我需要测试在正常 Activity 生命周期中丢失 EGL 上下文并重新创建表面时的行为,但是无论我做什么,我都无法将应用置于这种情况。

我可以做些什么来模拟再次调用 onSurfaceCreated 的情况?如何让我的应用失去 EGL 上下文?

编辑:几天后,我注意到问题消失了,应用程序开始正常运行,如规范中所述:

public abstract void onSurfaceCreated (GL10 gl, EGLConfig config)
Called when the surface is created or recreated.
Called when the rendering thread starts and whenever the EGL context is lost.
The EGL context will typically be lost when the Android device awakes 
after going to sleep

在此之前,每次设备进入休眠状态时, Activity 都会被破坏并在唤醒时重新创建,这使我无法测试 OnSurfaceCreated 中的代码是否运行良好。

现在它在 sleep /唤醒时表现得更好 - 它通常不会破坏 Activity ,只是调用 OnSurfaceCreated 方法,这是我的目标。



Best Answer-推荐答案


我不确定,但我唯一能想到的就是使用相同的 GLSurfaceView.RendererGLSUrfaceView 切换为新的。 这应该会创建一个新的 EGL 上下文并再次调用 onSurfaceCreated()

关于android - GLSurfaceView 渲染器,如何强制重新创建表面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16046918/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://www.ogeek.cn/) Powered by Discuz! X3.4