When I rotate my screen, the WebView reloads the whole page. So I disabled rotation in Android_Manifest.xml file, but it would be really cool if I could make rotation possib
There are 3 points must be done. This is a full solution for me.
AndroidManifest.xml need config both orientation and screenSize in android:configChanges for target activity
Need to override onSaveInstanceState and onRestoreInstanceState of Activity to make state can be restore when rotated
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
mWebView.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
mWebView.restoreState(savedInstanceState);
}
Not loading URL again when screen rotate, use savedInstanceState to know current status in onCreate() of target activity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
mWebView = (WebView) findViewById(R.id.webView_h5);
if (savedInstanceState == null) {
mWebView.loadUrl(url);
}
}
Miss any one of those three, my activity still reload.