Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Webview content should not be lost on orientation change, but GUI should be updated properly

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.

like image 927
Wottah Avatar asked Oct 09 '22 09:10

Wottah


1 Answers

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

like image 128
jp36 Avatar answered Oct 12 '22 10:10

jp36