diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45702.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45702.cs new file mode 100644 index 000000000..0c99344e1 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45702.cs @@ -0,0 +1,37 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 45702, "Disabling back press on modal page causes app to crash", PlatformAffected.Android)] + public class Bugzilla45702 : TestNavigationPage + { + protected override void Init() + { + Navigation.PushAsync(new NavigationPage(new MasterDetailPage() { Master = new ContentPage() { Title = "Master" }, Detail = new DetailPage() })); + + MessagingCenter.Subscribe(this, "switch", SwitchControl); + } + + void SwitchControl(object sender) + { + Application.Current.MainPage = new NavigationPage(new ContentPage { Content = new Label { Text = "Success" } }); + } + + class DetailPage : ContentPage + { + public DetailPage() + { + var button = new Button { Text = "Click me" }; + button.Clicked += Button_Clicked; + Content = button; + } + + void Button_Clicked(object sender, System.EventArgs e) + { + MessagingCenter.Send(this, "switch"); + } + } + } +} \ 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 0d7c09730..9805d4b13 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 @@ -336,6 +336,7 @@ + diff --git a/Xamarin.Forms.Controls/App.cs b/Xamarin.Forms.Controls/App.cs index c9989f344..b2616c0be 100644 --- a/Xamarin.Forms.Controls/App.cs +++ b/Xamarin.Forms.Controls/App.cs @@ -34,7 +34,7 @@ namespace Xamarin.Forms.Controls SetMainPage(CreateDefaultMainPage()); //// Uncomment to verify that there is no gray screen displayed between the blue splash and red MasterDetailPage. - //MainPage = new Bugzilla44596SplashPage(() => + //SetMainPage(new Bugzilla44596SplashPage(() => //{ // var newTabbedPage = new TabbedPage(); // newTabbedPage.Children.Add(new ContentPage { BackgroundColor = Color.Red, Content = new Label { Text = "yay" } }); @@ -43,7 +43,10 @@ namespace Xamarin.Forms.Controls // Master = new ContentPage { Title = "Master", BackgroundColor = Color.Red }, // Detail = newTabbedPage // }; - //}); + //})); + + //// Uncomment to verify that there is no crash when switching MainPage from MDP inside NavPage + //SetMainPage(new Bugzilla45702()); } public Page CreateDefaultMainPage() diff --git a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs index 62e1b32f0..d2ba44b04 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs @@ -128,20 +128,6 @@ namespace Xamarin.Forms.Platform.Android.AppCompat { _disposed = true; - // API only exists on newer android YAY - if ((int)Build.VERSION.SdkInt >= 17) - { - FragmentManager fm = FragmentManager; - - if (!fm.IsDestroyed) - { - FragmentTransaction trans = fm.BeginTransaction(); - foreach (Fragment fragment in _fragmentStack) - trans.Remove(fragment); - trans.CommitAllowingStateLoss(); - fm.ExecutePendingTransactions(); - } - } if (_toolbarTracker != null) { @@ -206,6 +192,21 @@ namespace Xamarin.Forms.Platform.Android.AppCompat } Device.Info.PropertyChanged -= DeviceInfoPropertyChanged; + + // API only exists on newer android YAY + if ((int)Build.VERSION.SdkInt >= 17) + { + FragmentManager fm = FragmentManager; + + if (!fm.IsDestroyed) + { + FragmentTransaction trans = fm.BeginTransaction(); + foreach (Fragment fragment in _fragmentStack) + trans.Remove(fragment); + trans.CommitAllowingStateLoss(); + fm.ExecutePendingTransactions(); + } + } } base.Dispose(disposing);