What is the right way to handle Activity lifecycle using OpenGL

I am really fighting here, and it holds me back.

What is the correct way to handle OpenGL and Activity - launches sub-actions or returns to the main screen. And let him resume exactly where he was.

I have a semi-work, as it stands, the textures / VBOs are reloaded with onResume () when necessary.

But sometimes when starting an auxiliary action and returning or exiting to the main screen and returning, onCreate starts again. This will ruin it all, and I get a black screen.

I am sure that I am doing everything wrong. Can someone explain how to handle such an action?

+6
android opengl-es
source share
1 answer

What platform are you working with?

The reason I ask is because before Eclair this whole area was riddled with errors, as a result of which the suspension / resumption of OpenGL basically worked only by accident. However, it looks like they were fixed with Eclair, and our application seems to pause and resume reliably enough.

What you have to do is register a callback to SurfaceHolder so that you get a notification when the surface appears and disappears. In the surfaceDestroyed () method, you completely close the EGL, and then in the surfaceCreated () method you reinitialize it. You should not do this from the Activity onCreate () / onResume () methods, since the surface may not display and disappear at the same time.

However, our app was developed for Cupcake when everything was pretty primitive. I understand that these days there are utility classes available that make it hard for you, so if you use one of these things, you can work differently; and if you do not, you can look in them.

+1
source share

All Articles