WebView1.Back Stops Working on Rotation

cbanks

Active Member
Licensed User
Longtime User
My app uses a WebView to display content. When users rotate the device they can no longer go back to previous pages. Is there a way to allow them to WebView1.Back after screen rotation? The history of pages they've been to seems to get lost.
 

warwound

Expert
Licensed User
Longtime User
Hi again!

As you've discovered - the WebView's WebBackForwardList is destroyed when the device orientation changes.

Take a look at the documentation for the native WebView saveState method:

public WebBackForwardList saveState (Bundle outState)

Can we use the Reflection library to:

In Activity_Pause:

1) Create a new Bundle.

2) Pass that Bundle to the WebView's saveState method.

3) Save that Bundle (which now contains the WebBackForwardList) as a Process Global.

In Activity_Create OR Activity_Resume:

4) Pass the saved Bundle to the WebView's restoreState method.

I think you'd have to call restoreState in Activity_Create, this is from the documentation:

This method should be called to restore the state of the WebView before using the object. If it is called after the WebView has had a chance to build state (load pages, create a back/forward list, etc.) there may be undesirable side-effects.

Have you got any experience with the Reflection library - i'm not sure what syntax would be used to create a new Bundle.

Maybe someone else could help with this..?

Martin.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I'm just saving the current URL as a global var, works any how...
 
Upvote 0

warwound

Expert
Licensed User
Longtime User

Too true...

The article you posted more or less sums it up.

There's just too many unknowns in any WebView for any 'restore-on-orientation-change' 'automatic-solution' to work.

Scroll position and zoom level being the main problems with a text based webpage - here's a related link: http://www.b4x.com/forum/basic4andr...save-current-url-page-position.html#post80325...

Imagine a WebView containing a javascript generated Google map.
On orientation change the whole page must reload and wait for javascript to re-create the map and then restore the map to it's previosuly viewed state - this is a problem for me and i'm looking at ways to introduce the MapView to B4A but with zero success so far http://www.b4x.com/forum/libraries-developers-questions/11304-mapview-non-starter.html#post63169.

As the article states - it's not easy.

Martin.
 
Upvote 0

Roeschti

Member
Licensed User
Longtime User
Yeah...do you know what I love most? Sentences like "It is possible to create a MapView library however it is not simple"

This always makes me smile

And I can also tell you: It's possible to write the next world number one hit game, but it is not simple :D

just kidding!

I stopped working on it, with my webviewextender library I just save scroll positions, url, zoom levels and reload it, set the scroll positions and zoom levels, finito.
 
Upvote 0

Gargoyle

Member
Licensed User
Longtime User
I stopped working on it, with my webviewextender library I just save scroll positions, url, zoom levels and reload it, set the scroll positions and zoom levels, finito.

@Roeschti, I know it's been a while since your post above, but I'd thought I'd ask anyway.

Could you (or anyone else) post an example of doing that (where different pieces go in what subs).
I've got something done, but doesn't seem to scroll/set positions properly.

Thanks.
 
Upvote 0
Top