Google Groups

Re: [android-developers] Activity#onRetainNonConfigurationInstance vs Fragment#setRetainInstance

Dianne Hackborn Apr 15, 2011 2:53 PM
Posted in group: Android Developers
Sorry, you just can't re-use a WebView across config changes -- a view is instantiated with a Context it runs in, which is the Activity that created it.  You can't change this context later, when you have a new Activity instance.

On Fri, Apr 15, 2011 at 8:33 AM, Shri <> wrote:
I have a WebView in my Activity which I want to reuse across config
changes so that the webpage does not get reloaded after every
orientation change. I can use
for this. However, I have heard that Fragment#setRetainInstance is
better for this purpose. This does not seem correct if there are other
Views involved which should be recreated after a config change (eg.
TextView which should be recreated after a locale change so that new
string resources can be picked up). I could keep only the WebView in a
Fragment, and all other Views in the Activity, but then either
approach seems good enough.

Just checking that Activity#onRetainNonConfigurationInstance/
getLastConfigurationInstance are not considered to be bad practice
going forward.
only mentions these apis anyway, not Fragment#setRetainInstance.


You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.