ADB
ADB

Reputation: 2329

GLSurfaceView: Do I need to to call onPause/onResume?

I am using a GLSurfaceView (sdk version 7) in RENDERMODE_WHEN_DIRTY. The documentation says I need to call onPause/onResume, but it works fine without it, so I am wondering. Is it required? What can happen if I don't?

Upvotes: 5

Views: 3674

Answers (1)

Lior
Lior

Reputation: 7915

The implementation of GLSurfaceView's onPause looks like this:

/**
 * Inform the view that the activity is paused. The owner of this view must
 * call this method when the activity is paused. Calling this method will
 * pause the rendering thread.
 * Must not be called before a renderer has been set.
 */
public void onPause() {
    mGLThread.onPause();
}

You can see (and the documentation states) that it pauses the rendering thread. This causes an internal call in the GLThread to stopEglLocked which looks like this:

 private void stopEglLocked() {
        if (mHaveEgl) {
            mHaveEgl = false;
            mEglHelper.destroySurface();
            mEglHelper.finish();
            sGLThreadManager.releaseEglSurface(this);
        }
 }

So you can see it destroys the surface which is an expensive system resource, and causes thread to wait(), which also saves system resources, cpu, baterry, etc.

So, calling GLSurfaceView's onPause and onResume is definitely required.

Upvotes: 12

Related Questions