I'm using OpenGL ES 2.0 on Android to make a basic game. I discovered that if I hit the home key on my device (emulator or real device) when the GLSurfaceView is present and then log back into the app from the Android home screen the app will crash. In contrast, if I I hit the back key while the GLSurfaceView is present which then takes me back to my MainActivity / MainView then everything is fine. I assume this has to do with how the GL Thread is managed, and when I close the app immediately the state is saved as opposed to being popped off the activity stack like when I hit the back button to go to my MainActivity.
My question is how should I best deal with destroying the GLSurfaceView state information? If the user hits the home key I want the information to reset and not be saved. Should I override onStop in the class that implements GLSurfaceView.Renderer and delete the GLSL program?
I can give a rough picture of how my activites are laid out below.
MainActivity class:
public MainActivity extends Activity
GameView view;
public onCreate ( ... ) { }
GameView class:
public GameView extends GLSurfaceView
Renderer renderer;
public onCreate (...) { // set EGL information and renderer };
Renderer class:
public Renderer implements GLSurfaceView.Renderer
// implements the surface change, created, and draw methods