1

In my application I use only WebView for loading index.html where running all app logic(html's and javascript).

Where screen orientation changed, all data from JavaScript variables disappear.

How I can save all data when orientation changed?

smie
  • 592
  • 1
  • 9
  • 25

1 Answers1

4

You have to catch orientation changes and handle them by yourself, because by default the Activity gets recreated (and your WebView will be reloaded).

Add the android:configChanges attribute to your Activity in the AndroidManifest.xml

<activity ... android:configChanges="orientation|keyboardHidden|keyboard">

And override the onConfigurationChanged method in your Activity class.

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
}

Also have a look here: Activity restart on rotation Android

Community
  • 1
  • 1
Floern
  • 33,559
  • 24
  • 104
  • 119
  • This method don help. In onCreate() I call loadWebPage() method where I load index.html. If I call them from onConfigurationChanged() I back to index.html – smie Jun 20 '12 at 15:02
  • 1
    You don't need to call anything in `onConfigurationChanged`. Just copy&paste the code from above without modifications. – Floern Jun 20 '12 at 15:11
  • @Floern why your code doesn't preserve webivew data if we populate the webview using android get request and then rotate the screen? – user1788736 Nov 23 '17 at 03:21