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

Reply via email to