How to fix rotation on webview for Android phones?

后端 未结 4 1211
野性不改
野性不改 2021-01-15 04:48

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

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-15 05:24

    When you rotate the device, Android restarts the application to help reload the right configuration files. There are several ways to handle this. The main two are saving the state of the application and then reloading it after the configuration change, or telling Android not to reset the application for certain orientation changes. For your situation, I'd recommend the latter (because I've not worked much with the WebView). Here's how.

    Add this to your Activity(s) manifest, that you do not want restarted.

    < activity android:name=".MyActivity" android:configChanges="orientation" >

    And if you want to execute any code on the configuration change, add this to your Activity's code.

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    
        // Do something here
    }
    

提交回复
热议问题