3

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.

Android Dev Guide

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

4

2 回答 2

1

这两个方法在主线程(UI线程)中调用:YourActivity.onPause/YourGLSurfaceView.onPause

所以,也许应该在 YourGLSurfaceView.java 中这样:

public void onPause() {
    queueEvent(new Runnable() {
        @Override
        public void run() {
            3dcube.onPause();
        }
    });

    super.onPause();
}
于 2012-09-14T18:38:37.510 回答
0

您应该从 onpausse onresume() 方法注册/取消注册渲染器,它将完美运行

于 2012-09-24T04:49:17.353 回答