title: Configuring multiple Activities each containing a GLSurfaceView within a TabHost
body: <p>My set-up is as follows: a TabHost has two child Activities, each with a single GLSurfaceView as content. The two Activities are of course forwarding their onPause() and onResume() events to their GLSurfaceViews.</p>
  
  <p>The first Activity works as expected, however switching to the other tab has no visual impact.
  LogCat reveals that both onSurfaceCreated(), onSurfaceChanged() and onSurfaceDraw() are all invoked as expected on both GLSurfaceView instances.</p>
  
  <p>A "fix" is to set the visibility of each GLSurfaceView using setVisibility(View.INVISIBLE/VISIBLE) in onPause() and onResume() respectively. This causes the correct views to show, but has the downside of causing a flickering effect when changing tab. This is especially evident when the GLSurfaceView does more of a job.</p>
  
  <p>Essentially, how can I avoid having to set the VISIBILITY of the GLSurfaceViews?</p>
  
  <p>TabActivity:</p>
  
  <pre><code>    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainactivity);
  
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;
  
        // First Vortex view
        intent = new Intent().setClass(this, VortexActivity.class);
        spec = tabHost.newTabSpec("A")
              .setIndicator("A")
              .setContent(intent);
        tabHost.addTab(spec);
  
        // Second Vortex view
        intent = new Intent().setClass(this, VortexActivity.class);
        spec = tabHost.newTabSpec("B")
              .setIndicator("B")
              .setContent(intent);
        tabHost.addTab(spec);
  }
  </code></pre>
  
  <p>Child activity:</p>
  
  <pre><code>    public class VortexActivity extends Activity {
  
          private GLSurfaceView view;
  
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          view = new GLSurfaceView(this);
          view.setRenderer(new VortexRenderer());
              setContentView(view);
          }
  
        @Override
        public void onResume() {
          super.onResume();
          view.onResume();
          //view.setVisibility(View.VISIBLE);
        }
  
        @Override
        public void onPause() {
          super.onPause();
          view.onPause();
          //view.setVisibility(View.INVISIBLE);
        }
  
      }
  </code></pre>
  
  <p>Renderer:</p>
  
  <pre><code>    public class VortexRenderer implements GLSurfaceView.Renderer {
          public void onSurfaceCreated(GL10 glArgument, EGLConfig config) {
          }
          public void onSurfaceChanged(GL10 gl, int w, int h) {
          }
          public void onDrawFrame(GL10 gl) {
              long ms = System.currentTimeMillis() % 2000;
              if(ms &gt; 1000)
                  ms = 1000 - (ms - 1000);
              float intensity = ms / 500.0f;
              gl.glClearColor(intensity, intensity, intensity, 1.0f);
              gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
          }
      }
  </code></pre>
  
  <p>Layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" &gt;
  
  &lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:padding="0dp" &gt;
  
      &lt;FrameLayout
          android:id="@android:id/tabcontent"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:padding="0dp" /&gt;
  
      &lt;TabWidget
          android:id="@android:id/tabs"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0"
          android:padding="0dp" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>