[android-developers] Re: Keeping WebView history through orientation change?
On Mar 19, 10:21 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> On Sat, Mar 19, 2011 at 5:00 PM, Joseph S <joseph.santanie...@gmail.com> 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 ::
>
Thanks for the tip!
Just doing nothing (other than kicking it back upstairs with super) in
onConfigurationChanged seems to have solved my problem. The examples
dealing with onConfigurationChanged that I'd seen had UI's that needed
fiddling after orientation changes so that's why they broke lots of
stuff out of onCreate. But in my case that was just extra.
Joseph
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home