Reputation: 886
I'm having issues with my GLSurfaceView.
My main activity has a TabLayout. I put a GLSurfaceView inside a tab like this:
renderer = new GLRendererX(Interface.this);
cube3d = new GLSurfaceView(Interface.this);
cube3d.setRenderer(renderer);
cube3d.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
cube3d.setOnTouchListener(new OnTouch());
cube3d_tab_content = (LinearLayout) findViewById(R.id.tab1_5);
cube3d_tab_content.addView(cube3d);
According to the Android developer guide, I have to call the onPause() and onResume() methods:
A GLSurfaceView must be notified when the activity is paused and resumed. GLSurfaceView clients are required to call onPause() when the activity pauses and onResume() when the activity resumes. These calls allow GLSurfaceView to pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate the OpenGL display.
So I insertet the onResume()/onPause() calls in my main activity onResume()/onPause():
@Override
protected void onPause() {
super.onPause();
cube3d.onPause();
//cube3d_tab_content.removeView(cube3d);
currentTab = th.getCurrentTabTag();
}
and
@Override
protected void onResume() {
super.onResume();
cube3d.onResume();
if (prefs != null) {
protocol.refresh();
}
th.setCurrentTabByTag(currentTab);
cube.setFields(ffields, rfields, lfields, ufields, dfields, bfields);
cube.display();
}
Now, when I call another activity - for example over the menu - and come back (onResume), the activity is freezing for a couple of seconds and finally returns to my main activity.
To make sure that the issue occurs only with GLSurfaceView I removed the code concerning the GLSurfaceView. It worked as it should.
So I assume that something is wrong with my cube3d.onPause() / .onResume().
Does anyone know how to fix this?
Thanks in advance!
Adrian
Upvotes: 3
Views: 2571
Reputation: 5684
You should register/deregister the renderer from the onpausse onresume() method and it will work perfectly
Upvotes: 0
Reputation: 299
the two methods are called in main thread(UI thread): YourActivity.onPause/YourGLSurfaceView.onPause
so, maybe should like this in YourGLSurfaceView.java:
public void onPause() {
queueEvent(new Runnable() {
@Override
public void run() {
3dcube.onPause();
}
});
super.onPause();
}
Upvotes: 1