Preventing Android GL Context loss

跟風遠走 提交于 2019-12-06 09:27:18

On Android, you shouldn't forcefully retain the GL context. On mobile devices, depending on the device capabitilies, it is normal that your application is asked or expected to release the context (and later it will get it back).

Instead of retaining it, you should reload your game resources when the GL context is available again. A good place to do this is the Renderer.onSurfaceCreated event. This method is called by the GL renderer thread whenever your context is created or recreated (i.e. when your previously lost context is given back to you).

So you don't need to worry that the GL context is lost and you won't know about it: when the context is regained, onSurfaceCreated will ALWAYS be called, you can be sure about this.

On a side note, in an Android application, you should pause your GLSurfaceView in your Activity.onPause(), and resume it in your Activity.onResume(). These can be accomplished via GLSurfaceView.onPause() and onResume().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!