On Aug 4, 2012, at 2:54 PM, simpleweb <[email protected]> wrote: > 'm building an app that has a webview. The webview loses content when screen > orientation changes.
The reason for this is that, by default, whenever the configuration changes a new Activity is created. Rotate the screen, and the current Activity is destroyed and a new one is created. > I have tried several things that were suggested, but not working. I have > tried these: Can you elaborate on how they are not working? Are there any error messages/etc.? > http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/ This solves the issue by overriding the Activity.OnSaveInstanceState() and Activity.OnRestoreInstanceState methods: http://androidapi.xamarin.com/?link=M:Android.App.Activity.OnSaveInstanceState http://androidapi.xamarin.com/?link=M:Android.App.Activity.OnRestoreInstanceState This works by asking the WebView to save it's information (URL, screen position) and then restoring that information within the new Activity/WebView. However, in order for this to work you need to override the appropriate Activity methods. If you keep the same Java names, you won't actually be overriding them: partial class MyActivity { // BROKEN protected void onSaveInstanceState(Bundle outState) {...} // BROKEN protected void onRestoreInstanceState(Bundle savedInstanceState) {...} } You need to use the `override` keyword and properly capitalize the method names: partial class MyActivity { protected override void OnSaveInstanceState(Bundle outState) {...} protected override void OnRestoreInstanceState(Bundle savedInstanceState) {...} } > http://stackoverflow.com/questions/9766584/android-webview-content-should-not-be-lost-on-orientation-change-but-gui-should This works by disabling configuration changes altogether, thus ensuring that your Activity instance isn't destroyed. This _should_ work, but...how are you specifying this? DO NOT edit Properties\AndroidManifest.xml to set XML information for C# types; it's very tricky. You should instead use custom attributes: [Activity(MainLauncher=true, ConfigurationChanges=ConfigChanges.Orientation)] public partial class MyActivity : Activity { // ... } - Jon _______________________________________________ Monodroid mailing list [email protected] UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid
