public void ClearBackStack(bool includeLast) { DebugBackstack(); int backstackCount; Android.Support.V4.App.FragmentManager fm = SupportFragmentManager; backstackCount = fm.BackStackEntryCount; if (backstackCount == 0) { return; } if (includeLast) { for (int i = 0; i < backstackCount; i++) { fm.PopBackStackImmediate(); } } else { for (int i = 0; i < backstackCount - 1; i++) { fm.PopBackStackImmediate(); } } DebugBackstack(); }
public void PopFragmentsOfType(Type type) { while (SupportFragmentManager.Fragments.Last().GetType().IsSubclassOf(type)) { SupportFragmentManager.PopBackStackImmediate(); } }
private void ClearBackStack(FragmentManager fm) { while (fm.BackStackEntryCount > 0) { fm.PopBackStackImmediate(); } }
/// <summary> /// Replaces the fragment. /// </summary> /// <param name="fragment">Fragment.</param> public void replaceFragment(Android.Support.V4.App.Fragment fragment) { String fragmentName = fragment.Class.Name; System.Diagnostics.Debug.WriteLine(string.Format("========== Fragment Name ======== {0}", fragmentName)); Android.Support.V4.App.FragmentManager fragmentManager = this.SupportFragmentManager; bool popSuccess = fragmentManager.PopBackStackImmediate(fragmentName, 0); if (!popSuccess && fragmentManager.FindFragmentByTag(fragmentName) == null) { //Replace Fragment Android.Support.V4.App.FragmentTransaction ft = fragmentManager.BeginTransaction(); ft.Replace(Resource.Id.fragmentFrameLayout, fragment, fragmentName); ft.SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentFade); ft.AddToBackStack(fragmentName); ft.Commit(); } }
/// <summary> /// Pops the back stack of all entries upto but not including the tag /// </summary> /// <param name="tag"></param> public void PopBackStackToTag(string tag) { int backstackCount; Android.Support.V4.App.FragmentManager fm = SupportFragmentManager; backstackCount = fm.BackStackEntryCount; if (backstackCount == 0) { return; } for (int i = backstackCount; i > 0; i--) { if (fm.GetBackStackEntryAt(i - 1).Name == tag) { break; } fm.PopBackStackImmediate(); } }
private void ClearBackStack(FragmentManager fm) { while (fm.BackStackEntryCount > 0) { fm.PopBackStackImmediate(); } }