A simple way is to override onSaveInstanceState on your activity and call
saveState on your webview.

Then on your onCreate if the saved state bundle isn't null call restoreState
on the webview.

It should reset its layout, and remember its history.

On Sat, Mar 19, 2011 at 2:21 PM, Mark Murphy <[email protected]>wrote:

> On Sat, Mar 19, 2011 at 5:00 PM, Joseph S <[email protected]>
> wrote:
> > I have an Activity that has a WebView and my own WebViewClient. To
> > deal with orientation changes, I have configChanges in the manifest
> > and onConfigurationChanged.
> >
> > During onCreate and onConfigurationChanged I set up the views by
> > calling my own setupViews where I set the WebViewClient.
> >
> > For the onCreate I load a particular URL and the Activity does it's
> > thing.
> >
> > When the user changes the orientation of the device later on after
> > viewing a few pages, the onConfigurationChanged gets called, and I
> > load the URL the user was looking at (I saved it in a variable from my
> > WebViewClient's onPageStarted). This works, except the history is lost
> > because it's a new WebView.
> >
> > What's a better way of doing this? I want my WebViewClient to behave
> > like a normal browser when the user tilts the phone, just reloading
> > the current page and preserving the history.
>
> If you are using onConfigurationChanged(), leave the existing WebView
> alone. Use Java code to adjust your layout parameters and such to
> reflect the new orientation rather than inflate a new layout. If you
> leave the WebView alone, it should retain its history.
>
> This particular problem is one of the few good reasons to use
> onConfigurationChanged(). However, pretty much all of those reasons
> mean you really shouldn't load in a fresh layout file. Loading a fresh
> layout file might be used in demonstrations in some books (ahem) but
> isn't really the right production strategy.
>
> :: quick makes a note to really cover this scenario better in next
> update to that book ::
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Android Training in Oslo: http://bit.ly/fjBo24
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
~ Jeremiah:9:23-24
Android 2D MMORPG: http://solrpg.com/ http://www.youtube.com/user/revoltingx

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to