Save State of WebView when fragment containing the webview is replaced
<p>I am using webview to create a basic web browser,
Currently I have one activity and multiple fragments :</p>

<p>-- Browser
-- something else
--  Something else</p>

<p>in Browser Fragment I have the webview :</p>

<pre><code> &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".fragments.BrowserFragment"&gt;

    &lt;android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"&gt;

        &lt;RelativeLayout
            android:id="@+id/webview_holder"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true"&gt;
            &lt;include
                android:id="@+id/button_layout"
                layout="@layout/bottom_btn_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"/&gt;

            &lt;LinearLayout
                android:id="@+id/web_page_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/button_layout"
                android:orientation="vertical"&gt;

            &lt;/LinearLayout&gt;

            &lt;WebView
                android:id="@+id/web_page"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/button_layout"/&gt;


        &lt;/RelativeLayout&gt;

    &lt;/android.support.v4.widget.SwipeRefreshLayout&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>I am able to save the state of the webview on screen rotation , by using </p>

<pre><code>@Override
public void onSaveInstanceState(Bundle outState) {
    if(mWebView != null){
        mWebView.saveState(outState);
    }
    super.onSaveInstanceState(outState);

}
</code></pre>

<p>and  calling this OnActivityCreated :</p>

<pre><code> mWebView = (WebView)getActivity().findViewById(R.id.web_page);

        if (savedInstanceState != null){
            mWebView.restoreState(savedInstanceState);
        }else{
            mWebView.loadUrl(makeUrl(url));
        }
</code></pre>

<p>This works fine when screen rotates and activity is recreated.
But when I use navigation drawer and replace fragment in the same container and then try to come back to same fragment . The state of webview is lost.</p>

<p>I get the point that onSaveInstanceState() is not called when there is Fragment transaction. So I tried saving the webView state by calling onSaveInstanceState() from OnPause of the fragment. But in that case I get savedInstanceState as null in OnCreateView so I am not able to restore state.</p>

<p>I need to maintain state of multiple webviews and comeBack to them on click of a list.</p>

<p>I also tried saving webview, when onSave() is called in fragment, in a static HashMap in activity and try to assign it to webview of newFragment. But I get Blank screen in that case.</p>

<p>Could someone give me pointers how I can approach this.</p>