views:

40

answers:

1

I'm really struggling here, and it's holding me back.

What is the correct way to handle OpenGL, and an Activity - which launches sub-activities, or goes back to the home screen. And have it resume just exactly where it was.

I have it semi-working as it stands, textures/VBOs are reloaded at onResume() when needed.

But sometimes, when launching sub-activities and returning, or going to home screen and returning, onCreate is being triggered again. This messes up the whole thing, and I end up with a black screen.

I'm sure I'm doing the whole thing wrong. Can someone explain how one should handle an Activity like this?

+1  A: 

What platform are you working with?

The reason I ask is that prior to Eclair this whole area was riddled with bugs with the result that suspending/resuming OpenGL basically only worked by accident. However, these do seem to have been fixed by Eclair and our app seems to be suspending and resuming fairly reliably.

What you're supposed to do is to register a callback to your SurfaceHolder so you get notified when the surface appears and disappears. In the surfaceDestroyed() method you shut down EGL completely, and then in your surfaceCreated() method you reinitialise it. You shouldn't be doing any of this from your Activity's onCreate()/onResume() methods, as the surface may not appear and disappear at the same time.

That said, our application was designed for Cupcake, when things were pretty primitive. I gather that these days there are utility classes available that do all the heavy lifting for you, so if you're using one of those things may work differently; and if you're not, you may want to look into them.

David Given