From: Kevin Petit Date: Fri, 19 Jul 2019 10:50:02 +0000 (+0200) Subject: Fix - Prevent race condition between activity create and dispose. (#6596) X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~232^2~50 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84a4f1ca275e648b24076bc6f39cddb17868cdbd;p=platform%2Fcore%2Fcsapi%2Fxsf.git Fix - Prevent race condition between activity create and dispose. (#6596) --- diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs index eb20ae6..965fc39 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs @@ -3,6 +3,7 @@ using System; using System.ComponentModel; using System.Linq; +using System.Threading; using Android.App; using Android.Content; using Android.Content.Res; @@ -10,7 +11,6 @@ using Android.OS; using Android.Runtime; using Android.Support.V7.App; using Android.Views; -using Android.Widget; using Xamarin.Forms.Platform.Android.AppCompat; using Xamarin.Forms.PlatformConfiguration.AndroidSpecific; using Xamarin.Forms.PlatformConfiguration.AndroidSpecific.AppCompat; @@ -40,6 +40,8 @@ namespace Xamarin.Forms.Platform.Android bool _activityCreated; PowerSaveModeBroadcastReceiver _powerSaveModeBroadcastReceiver; + static readonly ManualResetEventSlim PreviousActivityDestroying = new ManualResetEventSlim(true); + // Override this if you want to handle the default Android behavior of restoring fragments on an application restart protected virtual bool AllowFragmentRestore => false; @@ -143,6 +145,9 @@ namespace Xamarin.Forms.Platform.Android application.PropertyChanged += AppOnPropertyChanged; + // Wait if old activity destroying is not finished + PreviousActivityDestroying.Wait(); + Profile.FramePartition(nameof(SetMainPage)); SetMainPage(); @@ -206,6 +211,8 @@ namespace Xamarin.Forms.Platform.Android protected override void OnDestroy() { + PreviousActivityDestroying.Reset(); + if (_application != null) _application.PropertyChanged -= AppOnPropertyChanged; @@ -215,6 +222,8 @@ namespace Xamarin.Forms.Platform.Android Platform?.Dispose(); + PreviousActivityDestroying.Set(); + // call at the end to avoid race conditions with Platform dispose base.OnDestroy(); }