android - onPause()/onResume() 中的 GLSurface 问题

标签 android opengl-es onresume glsurfaceview onpause

我的 GLSurfaceView 有问题。

我的主要 Activity 有一个 TabLayout。我将 GLSurfaceView 放在这样的选项卡中:

    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);

根据 Android 开发人员指南,我必须调用 onPause() 和 onResume() 方法:

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

所以我在我的主要 Activity onResume()/onPause() 中插入了 onResume()/onPause() 调用:

@Override
protected void onPause() {
    super.onPause();

    cube3d.onPause();
    //cube3d_tab_content.removeView(cube3d);

    currentTab = th.getCurrentTabTag();
}

@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();
}

现在,当我调用另一个 Activity - 例如通过菜单 - 并返回 (onResume) 时,该 Activity 会卡住几秒钟,最后返回到我的主要 Activity 。

为确保问题仅发生在 GLSurfaceView 上,我删除了有关 GLSurfaceView 的代码。它按预期工作。

所以我假设我的 cube3d.onPause()/.onResume() 有问题。

有人知道怎么解决吗?

提前致谢!

阿德里安

最佳答案

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

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

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

    super.onPause();
}

关于android - onPause()/onResume() 中的 GLSurface 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9233725/

相关文章:

java - Picasso IllegalArgumentException 目标不能为空 : Retrieve data from Firebase

javascript - THREE.js - 广告牌顶点着色器

android - 为什么unity OnApplicationPause在android上被调用两次?

java - 对两个 RxJava 可观察对象(Android)进行基准测试?

android - 检查通知是否处于 Activity 状态

android - 将 RadioButtons 从膨胀的 ListView 布局添加到 RadioGroup

android - 在 MALI 400 上让 SurfaceTexture 与 Android Videoplayer 一起工作时出现问题

iphone - 在 OpenGLES 中处理 iPhone 方向变化

android - 当方向改变发生时调用哪个 Activity 方法?

几个小时后恢复应用程序时出现 Android 异常