diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42075.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42075.cs new file mode 100644 index 000000000..fd599eade --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42075.cs @@ -0,0 +1,39 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls +{ + [Preserve (AllMembers = true)] + [Issue (IssueTracker.Bugzilla, 42075, "IllegalStateException - Fragment does not have a view", PlatformAffected.Android)] + public class Bugzilla42075 : TestTabbedPage + { + protected override void Init() + { + Title = "Outer"; + + const string text = @"To run this test, you'll need to have an emulator or device in Developer mode, with the ""Don't Keep Activities"" setting turned on. +Hit the Home button to dismiss the application. Then bring up the Overview (recent apps) screen and select the Control Gallery. +If the application crashes with ""Java.Lang.IllegalStateException: Fragment does not have a view"", this test has failed. If the application does not crash or crashes with a different exception, this test has passed."; + + var directions = new ContentPage + { + Content = new StackLayout() + { + Children = + { + new Label() + { + Text = text + } + } + } + }; + + var tabbedPage = new TabbedPage() {Title = "Inner"}; + tabbedPage.Children.Add(new ContentPage()); + + Children.Add(directions); + Children.Add(tabbedPage); + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 30ad7ee40..85c287f5c 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -110,6 +110,7 @@ + diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs index 6bd7df2b7..b6736df2b 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs @@ -44,6 +44,9 @@ namespace Xamarin.Forms.Platform.Android int _statusBarHeight = -1; global::Android.Views.View _statusBarUnderlay; + // Override this if you want to handle the default Android behavior of restoring fragments on an application restart + protected virtual bool AllowFragmentRestore => false; + protected FormsAppCompatActivity() { _previousState = AndroidApplicationLifecycleState.Uninitialized; @@ -139,8 +142,17 @@ namespace Xamarin.Forms.Platform.Android callback(resultCode, data); } + protected override void OnCreate(Bundle savedInstanceState) { + if (!AllowFragmentRestore) + { + // Remove the automatically persisted fragment structure; we don't need them + // because we're rebuilding everything from scratch. This saves a bit of memory + // and prevents loading errors from child fragment managers + savedInstanceState?.Remove("android:support:fragments"); + } + base.OnCreate(savedInstanceState); AToolbar bar;