I\'m writing an Android application that uses OpenGL ES (GLSurfaceView and GLSurfaceView.Renderer). The problem is that when the user switches applications and then switches
As mentioned in a comment above it is also possible to avoid trashing the GL context earlier Android releases (1.x, 2.x), the solution is to copy the GLSurfaceView from Android-15 SDK source code, change its package name, and then use your own copy of the GlSurfaceView.
It should work for devices which support multiple GL contexts (except for Adreno chips, at the moment), regardless of Android version. A caveat is that GLSurfaceView from Android-15 only contains the necessary stuff to work with android-15, our version must handle all OS-versions.
We use our own implemention of the GlSurfaceView based on a copy from ReplicaIsland, where Chriss Pruit also used his own implementation.
In our version we added the setPreserveEGLContextOnPause from SDK-15, which allows to preserve GL context on for instance a nexus one running android 2.3.
We have also changed other stuff to suit our needs, which is not relevant for this question (such as 32-bit rendering on phones which support it, otherwise 16bit).
Our GlSurfaceView: http://pastebin.com/U4x5JjAr
Here is the original SDK-15 version of the GlSurfaceView formatted by same (Android) style as above http://pastebin.com/hziRmB3E (so that it is easy to compare and see the changes)
Remember to enable the context preservation by calling:
glSurfaceView.setPreserveEGLContextOnPause(true);