Question

I have repeatedly read that onPause() and onResume() must be called for the GLSurfaceview during the onPause() and onResume() methods of the enclosing activity. I gather that this is to stop and restart the rendering thread to save resources. However, when I log each iteration of the onDraw method of the rendering thread, I see that onDraw stops being called when I press the home or back buttons, and when I return to the app, onSurfaceCreated and onSurfaceChanged get called, and then the onDraw call resume - even after I remove the calls to the GLSurfaceview's onPause() and onResume() methods in the corresponding activity methods. If the rendering thread is not being stopped, how am I seeing this behavior? Is the rendering thread still somehow alive even though onDraw is no longer being called? And if the rendering thread is being shut down automatically when the activity loses focus, then why is it necessary to call the GLSurfaceview versions of onPause() and onResume()?

Was it helpful?

Solution

It seems like a bug in GLSurfaceView where it tries to be clever by tolerating you forgetting to call onResume() and onPause(). I'm not sure if this is deliberate or not.

Leaving the calls out works almost always, but it can cause odd behaviour and crashes in some situations. I'm not exactly sure what those situations are, but I have traced a few weird crashes back to missing onResume()/onPause() calls. Something gets slightly messed up with the state machine in GLSurfaceView when you don't call them - it looks like the fallback logic to 'automatically' resume and pause doesn't get triggered in 100% of cases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top