Android webView saveState

This can be handled by overrwriting onSaveInstanceState(Bundle outState) in your activity and calling saveState from the webview:

@Override
protected void onSaveInstanceState(Bundle outState) {
    webView.saveState(outState);
    super.onSaveInstanceState(outState); 
}

Then recover this in your onCreate after the webview has been re-inflated of course:

@Override
public void onCreate(final Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.blah);
   WebView webview = (WebView)findViewById(R.id.webview);
   if (savedInstanceState != null)
      webview.restoreState(savedInstanceState);
   else
      webview.loadUrl(URLData)
}

Leave a Comment