codeNinja
codeNinja

Reputation: 1462

removing and re-adding a linear layout that holds a glSurfaceView causing nothing to be drawn on screen

I have a simple test app i am working on. This will be later imported into a larger application but i want to get it working first before i merge it with the actual application. It has 3 linearlayouts. The first one is the mainLayout and the other two are child1 and child2 of the mailLayout. In child open i place a GLSurfaceview and child2 i place a text view.

The glSurfaceView has a custom renderer that takes an 2d image and draws in on the screen for 7 seconds (streching it a little bit every onDrawFrame). After the 7 seconds the next image is to be loaded by the same Renderer and shown on screen. this repeats infinitely.

I have the first image showing properly. After the first seven seconds i remove child1 and child2 from the mainlayout. Then i load the second image and create the texture. Then i add the child1 and child2 back.

The problem i see is that nothing is being rendered on the screen. Also the none of the Renderers methods (onDrawFrame, onSurfaceChanged, or onSurfaceCreated) are being called.

If i dont remove child1 and child2 from the mainlayout the second image shows properly. The reason i need to remove all child from mainlayout is that in the real application there might be over overlaying layout/view that the user might have dragged onto the screen. They need to be removed before the next image.

What am i doing wrong here? Thanks for your help.

Upvotes: 1

Views: 763

Answers (1)

codeNinja
codeNinja

Reputation: 1462

So I found out that the GLSurfaceView was getting destroyed when I was removing it from the screen. I put a onDestroyListener on the glSurfaceView and noted it in a local boolean, isGLDestroyed. Next time before adding it to the screen I recreated the GlSurfaceView.

Let me know if this is not the most efficient way to solve the issue.

Upvotes: 1

Related Questions