diff --git a/MvvmCross.Droid.Support.V4/MvxCachingFragmentActivity.cs b/MvvmCross.Droid.Support.V4/MvxCachingFragmentActivity.cs index 334198d..9eecf16 100644 --- a/MvvmCross.Droid.Support.V4/MvxCachingFragmentActivity.cs +++ b/MvvmCross.Droid.Support.V4/MvxCachingFragmentActivity.cs @@ -32,6 +32,7 @@ public class MvxCachingFragmentActivity : MvxFragmentActivity, IFragmentCacheabl public const string ViewModelRequestBundleKey = "__mvxViewModelRequest"; private const string SavedFragmentTypesKey = "__mvxSavedFragmentTypes"; private IFragmentCacheConfiguration _fragmentCacheConfiguration; + private string _firstFragmentTag; protected enum FragmentReplaceMode { @@ -241,6 +242,17 @@ protected virtual void ShowFragment(string tag, int contentId, Bundle bundle, bo cache.GetAndClear(fragInfo.ViewModelType, GetTagFromFragment(fragInfo.CachedFragment as Fragment)); } + // Prevent to add the "same first" fragment twice + if (fragInfo.Tag == _firstFragmentTag) + { + SupportFragmentManager.PopBackStack(null, (int)PopBackStackFlags.Inclusive); + } + + if (string.IsNullOrEmpty(_firstFragmentTag)) + { + _firstFragmentTag = fragInfo.Tag; + } + if ((currentFragment != null && fragInfo.AddToBackStack) || forceAddToBackStack) { ft.AddToBackStack(fragInfo.Tag);