androidopengl-esopenglcontext

Check if gl context was destroyed


Is there way to detect if opengl context was disposed when user has pressed home button?Currently I always recreate whole glSurface in onResume method.Also there is setPreserveEGLContextOnPause which might keep context alive.I'd like to use it to not recreate glSurface each time.The question is how to detect if I need to recreate it?


Solution

  • Check if eglGetCurrentContext() returns EGL_NO_CONTEXT.

    I'd like to use it to not recreate glSurface each time

    Note this is bad practise - it means that your process hogs more memory when it's not in use. In many cases this just means Android will simply kill your process completely if the foreground process needs more memory.