I\'m trying to figure out how to fix the orientation problem on webview. Basically every time the user changes the orientation on the device the program goes white and reloa
I had the same problem. The reason that the webView restarts when you flip the screen (in my case at least) is that you always initialize the webView when onCreate() runs, even though the webView is not null.
First add the following in your AndroidManifest.xml:
Then, try adding an if-clause:
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Add this
if(webView == null){
webView = (WebView)findViewById(R.id.webView);
WebSettings webSettings =webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient (new HelloWebViewClient());
webView.loadUrl("http://google.com");
}
if (savedInstanceState != null)
((WebView)findViewById(R.id.webView)).restoreState(savedInstanceState);
}
...