title: Android App Crashed by using texureview
body: <p>We are working to show video through <code>texureview</code> which requires hardware acceleration.
  Everything is good and life is happy untill we encouter this problem occurs.</p>
  
  <p>Here is the crash stack info:</p>
  
  <pre>
  12-25 19:49:24.951 E/SurfaceTexture( 6432): [unnamed-6432-2](this:0x605`enter code here`b5620,api:0) **detachFromContext: invalid current EGLContext**
  12-25 19:49:24.951 D/AndroidRuntime( 6432): Shutting down VM
  12-25 19:49:24.951 W/dalvikvm( 6432): threadid=1: thread exiting with uncaught exception (group=0x41a719a8)
  12-25 19:49:24.964 W/System.err( 6432): java.lang.RuntimeException: Error during detachFromGLContext (see logcat for details)
  12-25 19:49:24.964 W/System.err( 6432):     at android.graphics.SurfaceTexture.detachFromGLContext(SurfaceTexture.java:217)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.TextureView.destroySurface(TextureView.java:226)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.TextureView.access$000(TextureView.java:105)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.TextureView$1.run(TextureView.java:214)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.HardwareRenderer$Gl20Renderer.safelyRun(HardwareRenderer.java:1605)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.TextureView.onDetachedFromWindow(TextureView.java:211)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.View.dispatchDetachedFromWindow(View.java:12039)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.964 W/System.err( 6432):     at android.view.ViewGroup.removeDetachedView(ViewGroup.java:3940)
  12-25 19:49:24.964 W/System.err( 6432):     at android.widget.AbsListView.access$5900(AbsListView.java:102)
  12-25 19:49:24.964 W/System.err( 6432):     at android.widget.AbsListView$RecycleBin.clear(AbsListView.java:6875)
  12-25 19:49:24.964 W/System.err( 6432):     at android.widget.AbsListView.onDetachedFromWindow(AbsListView.java:2720)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.View.dispatchDetachedFromWindow(View.java:12039)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2618)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.965 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2616)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2958)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.ViewRootImpl.doDie(ViewRootImpl.java:4557)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.ViewRootImpl.die(ViewRootImpl.java:4538)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:338)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:288)
  12-25 19:49:24.966 W/System.err( 6432):     at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:84)
  12-25 19:49:24.966 W/System.err( 6432):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3662)
  12-25 19:49:24.967 W/System.err( 6432):     at android.app.ActivityThread.access$1200(ActivityThread.java:156)
  12-25 19:49:24.967 W/System.err( 6432):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1395)
  12-25 19:49:24.967 W/System.err( 6432):     at android.os.Handler.dispatchMessage(Handler.java:99)
  12-25 19:49:24.967 W/System.err( 6432):     at android.os.Looper.loop(Looper.java:153)
  12-25 19:49:24.967 W/System.err( 6432):     at android.app.ActivityThread.main(ActivityThread.java:5338)
  12-25 19:49:24.967 W/System.err( 6432):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-25 19:49:24.967 W/System.err( 6432):     at java.lang.reflect.Method.invoke(Method.java:511)
  12-25 19:49:24.967 W/System.err( 6432):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
  12-25 19:49:24.967 W/System.err( 6432):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  12-25 19:49:24.968 W/System.err( 6432):     at dalvik.system.NativeStart.main(Native Method)
  </pre>
  
  <p>From the info above we find something wrong happened in <code>SurfaceTexture.cpp</code></p>
  
  <pre><code>if (mEglContext != ctx &amp;&amp; mEglContext != EGL_NO_CONTEXT) {
      ST_LOGE("detachFromContext: invalid current EGLContext");
      return INVALID_OPERATION;
  }
  </code></pre>
  
  <p>We are using cached textureview through <code>listview</code>, but we don't know if this is the problem. We are not good at <code>OpenGL</code> and we know little about the mechanics of hardware acceleration.</p>
  
  <p>Can someone help?</p>