Search code examples
androidandroid-ndkpowervr-sgx

how to restore my android game's nativeactivity (GLES layer) after phone call ends?


I am running GLES2 using native activity in my android app. When a call ends, I return to my app but the screen remains blank. I check the task manager, and I see that the app is still running. Can someone point me if 1) I have to write code to save and restore my game and which calls I must override in java to do this 2) there is a more automated way of restoring my app without save/restore

Thanks, Madan


Solution

  • This is likely due to the fact that Android destroys the OpenGL Context after the application it sent to the background and doesn't by default automatically restore it.

    There's two options to resolve this - the easiest, if you're targeting Honeycomb devices or higher, is to use setPreserveEGLContextOnPause on your GLSurfaceView (see here). The alternative, if you're targeting a lower OS version is to restore everything manually. When the context is destroyed so is everything attached to it - shaders, textures, vertex and index buffers. You'll need to recreate these at the correct time - during onSurfaceCreated. Refer to the Android documentation for more details.

    UPDATE - Example implementation from my engine for pre-HoneyComb devices is here. See the code wrapped within PIXELBOOST_GRAPHICS_HANDLE_CONTEXT_LOST. The bindings to call the recreation of the context are in an example project.