My Webview Reloads When I Change From Portrait To Landscape

后端 未结 7 909
刺人心
刺人心 2021-01-01 17:25

I have a simple WebView that runs a web application on an Android. The problem is when I rotate the phone to change it to landscape the webview rel

相关标签:
7条回答
  • 2021-01-01 18:18

    Add this before the oncreate

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

    Write the oncreate this way. put final

    public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layoutname);
    if (savedInstanceState != null)
    {
    ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
    }
    else
    {
    webview.loadUrl("http://www.playbuzz.org/");
    }
    
    }
    

    In Androidmanifest insert under the activity

    android:configChanges="keyboardHidden|orientation"
    
    0 讨论(0)
提交回复
热议问题