mixi-inc/triaina — pull request #29 by ypresto (2014-01-14 05:05:27+00:00)
Title: Fix possible random NPE in AbstractWebViewBridgeFragment

* AbstractWebViewBridgeFragment.onDestroyView() calls WebView.destroy().
* AbstractWebViewBridgeFragment.onSaveInstanceState() calls
WebView.saveState().
* WebView in at least Android 4.0 seems to throw NPE when saveState()
called after destroy().
* onSaveInstanceState() is NOT guaranteed to be called before
onDestroyView().
* Hense, random crash may occur.

Refer:
http://stackoverflow.com/questions/15313598/once-for-all-how-to-correctly-save-instance-state-of-fragments-in-back-stack

For reproducing WebView NPE bug, below code crashes with NPE in Android 4.0.3.
(activity_main.xml includes LinearLayout with android:id="@+id/hoge".)

```java
package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.ViewGroup;
import android.webkit.WebView;

public class MainActivity extends Activity {

WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = new WebView(this);
mWebView.loadUrl("http://example.com/");
((ViewGroup) findViewById(R.id.hoge)).addView(mWebView);
}

@Override
public void onBackPressed() {
((ViewGroup) findViewById(R.id.hoge)).removeView(mWebView);
mWebView.destroy();
mWebView.saveState(new Bundle());
}
}
```