title: Android OpenGL ES 2.0 - Using glDelete* in onDestroy()
body: <p>I want to free textures, buffers and shaders in my android game, if user hit Back button, calls <strong>finish()</strong> method of activity, leading into <strong>onDestroy()</strong>, which i overrided to clean game data, close server connections and so on.<br>
  I set <strong>android:launchMode="singleTask"</strong> in my manifest, so calling finish() of activity always leads to destroying right away.<br>
  But to use <strong>glDeleteBuffers(...)</strong>, for example, it must be called from thread with EGL context (Renderer thread), but even if set and call such methods from Renderer class, i get - No OpenGL ES context error.</p>
  
  <p>I use NDK, so <strong>NativeLib.*</strong> calls a C/C++ functions like</p>
  
  <pre><code>JNIEXPORT void JNICALL /*class path*/_NativeLib_onDrawFrame(JNIEnv* env, jclass _class)
  {
   glClear(GL_COLOR_BUFFER_BIT);
   ...
  }
  </code></pre>
  
  <p>View  </p>
  
  <pre><code>public class OGLES2View extends GLSurfaceView
  {
  
    private static class OGLES2Renderer implements GLSurfaceView.Renderer
    {
      public void onDrawFrame(GL10 unused)
      {
          NativeLib.onDrawFrame();
      }
  
      public void onSurfaceChanged(GL10 unused, int width, int height)
      {
          NativeLib.onSurfaceChanged(width, height);
      }
  
      public void onSurfaceCreated(GL10 unused, EGLConfig unusedConfig)
      {
          NativeLib.onSurfaceCreated();
      }
  
      public void onSurfaceDestroy()
      {
          Log.i(LOG_TAG, "Destroying Opengl objects");
          NativeLib.onGLDestroy();//Don't work - call to OpenGL API with current context
      }
  
  }
  
  public OGLES2Renderer renderer = null; 
  public OGLES2View(Context context)
  {
      super(context);
      setRenderer(renderer = new OGLES2Renderer());
  }
  </code></pre>
  
  <p>in Activity</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      ogles2View = new OGLES2View(this);
      setContentView(ogles2View);
  }
  
  @Override
  protected void onDestroy()
  {
      Log.i(LOG_TAG, "Got finish request for game");
      super.onDestroy();
      ogles2View.render.onSurfaceDestroy(); // Don't not work
  }
  </code></pre>