title: Android - Preventing WebView reload on Rotate
body: <p>When I rotate my screen, the WebView reloads the whole page. I can't have this since some of my content contains dynamic/random material. Currently when rotated the screen reloads the original URL from the loadUrl() method. </p>
  
  <p>Any idea what's wrong with my code? </p>
  
  <p><em><strong>MainActivity.java</em></strong></p>
  
  <pre><code>package com.mark.myapp;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.KeyEvent;
  import android.view.Menu;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class MainActivity extends Activity {
  
      WebView web;
      String webURL = "http://www.google.co.uk/";
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          if (savedInstanceState != null)
              ((WebView)findViewById(R.id.web)).restoreState(savedInstanceState);
  
          web = (WebView) findViewById(R.id.web);
          web.getSettings().setJavaScriptEnabled(true);
          web.loadUrl(webURL);
          web.setPadding(0, 0, 0, 0);
          web.getSettings().setLoadWithOverviewMode(true);
          web.getSettings().setUseWideViewPort(true);
          web.getSettings().setSupportZoom(true);
          web.getSettings().setBuiltInZoomControls(true);
  
          web.setWebViewClient(new HelloWebViewClient());
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  
      private class HelloWebViewClient extends WebViewClient {
          public boolean shouldOverrideUrlLoading(WebView web, String url) {
              web.loadUrl(url);
              return true;
          }
      }
  
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          if ((keyCode == KeyEvent.KEYCODE_BACK) &amp;&amp; web.canGoBack()) {
              web.goBack();
              return true;
          }
          return super.onKeyDown(keyCode, event);
      }
  
  }
  </code></pre>
  
  <p><em><strong>AndroidManifest.xml</em></strong></p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mark.myapp"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="15" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
  
              android:configChanges="orientation|keyboardHidden"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;/manifest&gt;
  </code></pre>