Reuse of GLsurfaceView in 2 activities
I am working on a OpenGL开发者_如何学Python ES project, newbie stadium, so I got a question regarding a GLSurfaceView and Renderer implementation. I have a layout that contains GLSurfaceView in FrameLayout which I use to show the rendered animation (the animation is rendered in Renderer implementation of my own).
All this happens in one Activity.
Then I need to start another activity, but to use the same View and the same Renderer, I tried to create new GLSurfaceView in the new activity (also in FrameLayoyt, the same as the first Activity), but it crashes right away. So I think that I have to reuse the GLSurfaceView and the Renderer that I use in the first activity.
What is the right way to achive this?
Take a read this Android documentation page: GLSurfaceView
It does say:
Activity Life-cycle
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 suggest you to do the following:
private GLSurfaceView mGlSurface;
@Override
protected void onResume() {
super.onResume();
mGlSurface.onResume();
}
@Override
protected void onPause() {
super.onPause();
mGlSurface.onPause();
}
Hope this help.
精彩评论