I have a WebView with data populated from local javascript (in the “asset” folder). The WebView takes several seconds to load so I’d like to keep it on device rotation. I don’t want to use configChanges since it has some other collateral effects.
It seems to me that the best approach is to make a Picture from the WebView and load the Picture instead of the WebView on rotation but I can’t figure out how.
Here is the code I tried:
Canvas canvas = new Canvas();
pictureNightDay.draw(canvas);
Bitmap b = Bitmap.createBitmap(pictureNightDay.getWidth(), pictureNightDay.getHeight(),Config.ARGB_8888);
myWebViewNightDay.draw(new Canvas(b));
but this only shows a blank View.
The “pictureNightDay” was previously saved with
pictureNightDay = myWebViewNightDay.capturePicture();
Thanks, bye
Maurizio
At last I came with the following answer: I used two Views, one WebView and one ImageView (initially hidden)
Save the picture when WebView is loaded:
(pictureNightDay is a static field).
Then on rotation check if pictureNightDay is not null and swap the ImageView and WebView visibility: