GLSurfaceView inside fragment not rendering when restarted

I have a GLSurfaceView set up and rendering as expected using a GLSurfaceView.Renderer. My App uses fragments from the android support package. When I navigate to a new fragment surfaceDestroyed is called but when I come back to the fragment via the backstack the GLSurfaceView will not render, calls to requestRender do not result in an onDraw call.

I am aware that I need to call onResume and onPause on the surface view and I am doing this from the hosting fragment but it doesn't seem to solve the issue. All examples about htis method refer to the activity, could this be the issue? And if so how do you use a GLSurfaceView inside a fragment.

Any insight greatly appreciated, I'm happy to post code but it seems to be more of a general question to me,

Thanks


Here's how I have my GLSurfaceView setup in a fragment:

onCreateView() {
    glSurfaceView = new GLSurfaceView(getActivity());
   ...
}

onPause() {
    if (glSurfaceView != null) { glSurfaceView.onPause(); }
    ...
}

onResume() {
    if (glSurfaceView != null) { glSurfaceView.onResume(); }
    ...
}

}

So, similar to what you'd do in an activity. This works in my use case, so it seems like they do work in fragments. It's hard to say more without knowing what your code looks like.


I know it's too late but it may be useful for others This is my answer as i have already implemented it and it works well in both emulator and in device as well.i have use fragment and supportV4.Hope you will like it.

import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.opengles20.glsurfaceview.GlSurfaceViewClass;
import com.example.opengles20.renderer.RendererClass;

public class MYGlclass extends Fragment {
private GlSurfaceViewClass mGLView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    if (container == null) {
        return null;
    }
    View view=inflater.inflate(R.layout.main, container, false);
    mGLView=(GlSurfaceViewClasss)view.findViewById(R.id.gl_surface_view);
    mGLView.setEGLContextClientVersion(2);
    RendererClass rendererclass=new RendererClass(getActivity());
    mGLView.setRenderer(rendererclass);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    return view;
}
}