Articles‎ > ‎Android Articles‎ > ‎

Android WebView handling orientation changes save state

WebView Declaration:

WebView WebBrowser;

Code for WebView SaveState Mapping

public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browserPage);
WebBrowser = (WebView) findViewById(R.id.WebEngine);

if (savedInstanceState != null)
((WebView)findViewById(R.id.webview)).
restoreState(savedInstanceState);
else
WebBrowser.loadUrl(URLData);
}

SaveInstanceState Method

protected void onSaveInstanceState(Bundle outState) {
    WebBrowser .saveState(outState);
}