5

I have been trying to keep the loaded page and javascript values of a WebView on orientation change and pausing the activity. First I tried overriding configChanges, but that resulted in my GUI not being updated properly (i have a slidingdrawer that changes position on orientation change). After that i tried to put the WebView in a fragment and calling setRetainInstance(true); But this does not keep the content of the WebView intact. I tried keeping the same object alive by not recreating it, but android does not allow views to be re-used in that fashion.

my question is: is there any way to keep the contents of the webview without having to reload it on every orientation change, whilst having the other GUI components update properly.

I hope my question is clear enough, but i'd be happy to elaborate if there are any unclearities.

EDIT: i already tried adding android:configChanges="keyboardHidden|orientation" in my manifest, that is what i meant by "overriding configchanges"

It seems like the only solution is to update all javascript variables again on orientation change. As I have not yet ran huge chunks of updates through javascript, I cannot provide much insight regarding the speed and resources of this operation.

Wottah
  • 320
  • 2
  • 13

4 Answers4

4

I know you already tried

 android:configChanges="keyboardHidden|orientation"

but try this instead

android:configChanges="keyboardHidden|orientation|screenSize"

In Android 3.2 and up "screen size" changes when you rotate which causes the webview to recreate itself. see the linked answer below for more info.

I found this answer here https://stackoverflow.com/a/11903546/655822

Community
  • 1
  • 1
jp36
  • 1,873
  • 18
  • 28
0

Add this in your androidmanifest file..... activity

android:name=".YourActivityHere" 
android:configChanges="keyboardHidden|orientation"
Lucifer
  • 29,392
  • 25
  • 90
  • 143
Rashmi.B
  • 1,787
  • 2
  • 18
  • 34
  • I already tried that, that is what i meant by overriding configChanges. When i implement this my GUI will not be recreated, and my slidindrawer for instance will not update properly – Wottah Mar 20 '12 at 12:16
0

Try this put this in manifest

android:configChanges="orientation|keyboardHidden"></activity>

this in your class

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
5hssba
  • 8,079
  • 2
  • 33
  • 35
  • I already tried that, that is what i meant by overriding configChanges. When i implement this my GUI will not be recreated, and my slidindrawer for instance will not update properly – Wottah Mar 21 '12 at 07:14
0

Add below line in android Manifest file.

android:configChanges="keyboardHidden|orientation"

Yugandhar Babu
  • 10,311
  • 9
  • 42
  • 67
  • I already tried that, that is what i meant by overriding configChanges. When i implement this my GUI will not be recreated, and my slidindrawer for instance will not update properly. – Wottah Mar 19 '12 at 08:43