Preventing WebView reload on Rotate - Android Studio

后端 未结 3 1965
执笔经年
执笔经年 2020-12-09 22:53

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

3条回答
  •  囚心锁ツ
    2020-12-09 23:46

    All you need to do is Override onSaveInstanceState and onRestoreInstanceState.

    @Override
    protected void onSaveInstanceState(Bundle outState ){
        super.onSaveInstanceState(outState);
        mWebView.saveState(outState);
    }
    
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState){
        super.onRestoreInstanceState(savedInstanceState);
        mWebView.restoreState(savedInstanceState);
    }
    

    and one other solution could be to update your Activity tag in manifest to

    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    

提交回复
热议问题