My Android (OpenGL ES 2.0) game needs to be paused when user is minimizing it, without destroying what is already drawn on screen. Originally it used NativeActivity and pure C++, but it looks like it is not possible there. I have rewritten it and it is now Java generating custom GLSurfaceView and game logic+rendering is in C++. I added setPreserveEGLContextOnPause(true) when surface is created.
So the flaw after user click Home button is:
- onPause is sending nativeOnPause to C++ code through JNI
- C++ code sets pause variable which prevents updating and rendering
This works ok. After we get back to app:
- onResume calls nativeOnResume
- nativeOnResume calls EGL methods to get current context, display and surface and pass that to game manager.
- Updating and rendering is now activated
- We get few EGL_BAD_SURFACE messages and finally crash on eglMakeCurrent
The question is: should we in any way recreate EGLSurface and EGLDisplay using current context, or getting current surface and display is fine?
I also noticed that when we get back to app, onResume is called, but onSurfaceChanged or onSurfaceCreated is not called.
Any suggestion how to approach that problem on >4.0 devices?