fix MasterDetailPage dispose (#505)
authoradrianknight89 <adrianknight89@outlook.com>
Tue, 15 Nov 2016 22:35:24 +0000 (16:35 -0600)
committerE.Z. Hart <hartez@users.noreply.github.com>
Tue, 15 Nov 2016 22:35:24 +0000 (15:35 -0700)
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla46494.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla46494.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla46494.cs
new file mode 100644 (file)
index 0000000..bdb2415
--- /dev/null
@@ -0,0 +1,36 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Bugzilla, 46494, "Hardware/Software back button from MainPage of type MasterDetail causes crash 'java.lang.IllegalStateException: Activity has been destroyed'", PlatformAffected.Android)]
+       public class Bugzilla46494 : TestMasterDetailPage
+       {
+               protected override void Init()
+               {
+                       Master = new ContentPage { Title = "Master", BackgroundColor = Color.Blue };
+                       Detail = new NavigationPage(
+                               new ContentPage
+                               {
+                                       Title = "Detail",
+                                       BackgroundColor = Color.Red,
+                                       Content = new ContentView
+                                       {
+                                               Content = new Label
+                                               {
+                                                       Text = "Hit Back button to destroy Activity. Disposing Fragment should not run into a race condition with Activity destroy.",
+                                                       HorizontalTextAlignment = TextAlignment.Center,
+                                                       VerticalTextAlignment = TextAlignment.Center
+                                               }
+                                       }
+                               }
+                       );
+               }
+       }
+}
\ No newline at end of file
index fb70cf6..dc1e604 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44044.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44338.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla45743.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Bugzilla46494.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
index 35ddf2d..2fe5d5d 100644 (file)
@@ -185,15 +185,14 @@ namespace Xamarin.Forms.Platform.Android
 
                protected override void OnDestroy()
                {
-                       // may never be called
-                       base.OnDestroy();
-
                        MessagingCenter.Unsubscribe<Page, AlertArguments>(this, Page.AlertSignalName);
                        MessagingCenter.Unsubscribe<Page, bool>(this, Page.BusySetSignalName);
                        MessagingCenter.Unsubscribe<Page, ActionSheetArguments>(this, Page.ActionSheetSignalName);
 
-                       if (_platform != null)
-                               _platform.Dispose();
+                       _platform?.Dispose();
+
+                       // call at the end to avoid race conditions with Platform dispose
+                       base.OnDestroy();
                }
 
                protected override void OnNewIntent(Intent intent)