我有一个GLSurfaceView
渲染器,并且方法onSurfaceCreated
只被调用一次(基本上只有在创建或重新创建活动时)。
当 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
在此之前,每次设备进入睡眠状态时,活动都会被破坏并在唤醒时重新创建,这使我无法测试代码是否OnSurfaceCreated
运行良好。
现在,当睡眠/唤醒发生时,它的表现要好得多——它通常不会破坏活动,只是调用OnSurfaceCreated
方法,这是我的目标。