WebView and orientation change

warwound

Expert
Licensed User
Longtime User
Hi all.

I recently posted asking for help on a method to restore the state of a web page being displayed in a WebView when the device orientation changes.
(http://www.b4x.com/forum/basic4android-updates-questions/9632-pass-values-webpage-application.html)
I'm still looking for a solution (looks like i can use cookies to save the web page's state) but wonder how the native Android browser handles such orientation changes...

I have a ZTE Blade and an Advent Vega and on both devices i can browse to a web page, scroll down a bit (or otherwise change the view so it's not as it would be when the page is first loaded) and then flip the device.
The browser changes orientation and the web page (appears to) remain loaded exactly as it was before the orientation change.

With a WebView in a B4A app the WebView will reload the page - requesting all page elements again - and display the web page as it would display when first loaded.

How does the native browser do this?
Does it have access to properties of the WebView that it saves on actvity pause and restores on activity resume that effectively restore the WebView state (and state of the page displayed)?

Thanks.

Martin.

Edit: I think what i'm asking is - can i get the current HTML DOM structure and state from a WebView and restore that on orientation change?
Nothing in the WebView documentation looks like i can do this.
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Hi again.

After some more research i have found that the native WebView object has a saveState method.

This is the method signature: public WebBackForwardList saveState (Bundle outState)

Is the Reflector library of any use here?

Can i save the B4A WebView state on activity pause and restore it on activity resume?

The documentation says: "Please note that this method no longer stores the display data for this WebView".
Does that mean this method won't do as i expect - will it just save the WebView's history stack as a list of URLs?

Thanks for any help.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
:sign0148: that's a shame.

I thought i could simply change the project options to only support portrait view as a workaround BUT even though (visually) the display orientation does not change, the activity pauses and then resumes on orientation change so i'm back at square one!

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I stand corrected.

I've attached a little test app - on the emulator i press Ctrl-F11 or Ctrl-F12 to change orientation and it behaves as i described.
The activity pauses and resumes.

I tried it on my ZTE Blade though and its works as expected - no activity pause and resume.

Martin.
 

Attachments

  • OrientationChange.zip
    5.9 KB · Views: 420
Upvote 0
Top