title: How to fix Android WebView crash due to pending MotionEvent
body: <p>My Android app is experiencing this crash randomly during operation, and I think it is due to a pending MotionEvent that is dispatched to a null object, but not sure.</p>
  
  <p>here is the crash output:</p>
  
  <pre><code>java.lang.NullPointerException
  at android.webkit.BrowserFrame.getRequestInterceptor(BrowserFrame.java:1108)
  at android.webkit.FrameLoader.handleRequestIntercept(FrameLoader.java:426)
  at android.webkit.FrameLoader.handleHTTPLoad(FrameLoader.java:226)
  at android.webkit.WebViewWorker.handleMessage(WebViewWorker.java:124)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:143)
  at android.os.HandlerThread.run(HandlerThread.java:60)
  </code></pre>
  
  <p>My Android app manually creates a custom WebView and adds it to the ViewGroup in the Activity.onCreate() method like this:</p>
  
  <pre><code>ViewGroup groupA = (ViewGroup)findViewById(R.id.frame_layout_rowA);
  webViewRowA = new MyWebView(this);
  groupA.addView(webViewRowA);
  </code></pre>
  
  <p>The reason for doing it this way was to be able to get to the constructor for the WebView in order to pass <em>getApplicationContext()</em> instead of <em>this</em> to the constructor, which was a workaround for a memory leak in 2.1.</p>
  
  <p>The issue, I think, is that this Activity is restarted frequently.  This causes the normal chain of onStop(), onDestroy(), onCreate(), etc... to happen often. </p>
  
  <p>So my question is, could the crashes be due to a MotionEvent being dispatched to an instance of MyWebView that was attached to an old Activity that has been garbage collected?  Such as if the user clicked something in a webview right before this actvity was recycled?</p>
  
  <p>Another thing to note is I'm seeing these messages following a call to onDestroy()</p>
  
  <pre><code>/webviewglue(  436): nativeDestroy view: 0xd738d0
  </code></pre>
  
  <p>Any help or insight anyone might have, would be greatly appreciated.  I've been banging away at this issue for a while now.</p>
  
  <p>Oh, one other thing to note....this started happening in Android OS 2.2.  I've submitted a bug to Google, but not sure it is their issue.</p>
  
  <p>Thanks in advance.</p>