title: Android Pending Exception
body: <p>My app is a hybrid html5 + JS + android which run in webview and communicate so much with Andorid through JS interface.</p>
  
  <p>I got some report that it fails after 2 second on some devices. I added ACRA so I can get reports, but I didn't get any thing.</p>
  
  <p>So I tried to test it myself, To raise an exception I add a code that manipulate views of main thread in Javascript interface's function which was triggered with a button in html. This raise an exception: <strong>Only the original thread that created a view hierarchy can touch its views.</strong> Now the app start and when I tap the button it exit with exception and ACRA send the report.</p>
  
  <p>Then I put the manipulation code in a function of JS interface which was called immediately after the app start. now app is closed after a second. But ACRA doesn't send any error. Even an ExceptionHandler didn't catch it but catch the first case.</p>
  
  <p>This is the log of second scenario:</p>
  
  <pre><code>59): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@43f8d990 (uid=10019 pid=329)
  12-15 01:18:07.047: WARN/dalvikvm(409): JNI WARNING: JNI method called with exception raised
  12-15 01:18:07.047: WARN/dalvikvm(409): in Landroid/webkit/BrowserFrame;.stringByEvaluatingJavaScriptFromString (Ljava/lang/String;)Ljava/lang/String; (NewString)
  12-15 01:18:07.057: WARN/dalvikvm(409): Pending exception is:
  12-15 01:18:07.057: INFO/dalvikvm(409): Landroid/view/ViewRoot$CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views
  </code></pre>
  
  <p>I don't know what this pending exception is? I couldn't find anything on web. I wonder why dont ACRA or Exception Handler catch it?</p>
  
  <pre><code>class JavaScriptInterface
  {
      MyActivity parent;
      JavaScriptInterface(MyActivity parent)
      {
          this.parent = parent;
      }
  
      public void immediatelyCalled() 
      // Webview load index.html in oncreate of activity and js inside html calls this function immediately
      {
          parent.textview1.setText("test"); 
          // raise an exception which ACRA or Exception Handler dont catch
          // Problem is here
      }
  
      public void buttonCalled() 
      // This is called when a button is tapped in html
      {
          parent.textview1.setText("test"); 
          // raise an exception which Exception Handler and ACRA catch
      }
  }
  </code></pre>
  
  <p>this is my activity:</p>
  
  <pre><code>public class MyActivity extends Activity
  {
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
          class MyExceptionHandler implements Thread.UncaughtExceptionHandler
          {
              @Override
              public void uncaughtException(Thread thread, Throwable throwable)
              {
                  Log.d("ExceptionHandler", "Caught exception: " + throwable.getClass().getName() + ": " + throwable.getMessage());
              }
          }
  
          MyExceptionHandler handler = new MyExceptionHandler();
          Thread.setDefaultUncaughtExceptionHandler(handler);
  
  
          this.wv = (WebView) findViewById(R.id.webview);
          this.wv.addJavascriptInterface(new JavaScriptInterface(this), "android");
          this.ws = this.wv.getSettings();
          this.ws.setJavaScriptEnabled(true);
          this.wv.loadUrl("file:///android_asset/index.html");
  
      }
  }
  </code></pre>
  
  <p>this is part of index.html:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  android.immediatelyCalled();
  &lt;/scritp&gt;
  &lt;button onclick="android.buttonCalled()"&gt;&lt;/button&gt;
  </code></pre>
  
  <p>Tested on AVD 2.2 and Xperai Arc 4.0.3, Both the same</p>