Java Code Examples for android.support.v4.app.FragmentManager#popBackStackImmediate()

The following examples show how to use android.support.v4.app.FragmentManager#popBackStackImmediate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
private static void ShowFragment(FragmentActivity activity, String tag, Fragment fragment, String previous) {
    if (fragment == null) {
        Log.e(TAG, "Cannot show a null fragment, ShowFragment("+tag+") aborted.");
        return;
    }

    FragmentManager fm = activity.getSupportFragmentManager();

    //abort if fragment is already the current one
    Fragment current = fm.findFragmentById(R.id.fragment_placeholder);
    if(current != null && current.getTag().equals(tag))
        return;

    //try to pop back if the fragment is already on the backstack
    if (fm.popBackStackImmediate(tag, 0))
        return;

    //fragment is not there yet, spawn a new one
    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.anim.anim_enter_right, R.anim.anim_leave_left, R.anim.anim_enter_left, R.anim.anim_leave_right);
    ft.replace(R.id.fragment_placeholder, fragment, tag);
    ft.addToBackStack(previous);
    ft.commit();
}
 
Example 2
Source File: MainActivity.java    From funcodetuts with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    // Code here will be triggered once the drawer closes as we don't want anything to happen so we leave this blank
    mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    //calling sync state is necessary or else your hamburger icon wont show up
    mActionBarDrawerToggle.syncState();

    if (savedInstanceState == null) {
        // update the main content by replacing fragments
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        FragmentTransaction transaction = fragmentManager.beginTransaction();

        transaction.replace(R.id.container, new ContainerFragment());
        transaction.commit();
    }
}
 
Example 3
Source File: BrowsingActivityNavigationControllerDualPan.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void intializePansAfterRotation(int oldPanNumbers, @NonNull FragmentManager fragmentManager) {
    if (oldPanNumbers != paneNumber) {
        if (oldPanNumbers == 1) {
            Fragment oldBookInfo = fragmentManager.findFragmentByTag(BOOK_INFORMATION_FRAGMENT_TAG);
            if (oldBookInfo != null) {
                fragmentManager.popBackStackImmediate(BOOK_INFORMATION_FRAGMENT_ADDED, FragmentManager.POP_BACK_STACK_INCLUSIVE);
                fragmentManager.beginTransaction().remove(oldBookInfo).commit();
                fragmentManager.beginTransaction()
                        .replace(R.id.book_info_container, oldBookInfo, BOOK_INFORMATION_FRAGMENT_TAG)
                        .commit();

            }
            Fragment oldBookList = fragmentManager.findFragmentByTag(BOOK_LIST_FRAGMENT_TAG);
            if (oldBookList != null) {
                fragmentManager.popBackStackImmediate(BOOK_LIST_FRAGMENT_ADDED, FragmentManager.POP_BACK_STACK_INCLUSIVE);
                fragmentManager.beginTransaction().remove(oldBookList).commit();
                fragmentManager.beginTransaction()
                        .replace(R.id.book_list_container, oldBookList, BOOK_LIST_FRAGMENT_TAG)
                        .commit();

            }
        }
    }
}
 
Example 4
Source File: FragmentUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Pop to fragment.
 *
 * @param fm            The manager of fragment.
 * @param popClz        The class of fragment will be popped to.
 * @param isIncludeSelf True to include the fragment, false otherwise.
 * @param isImmediate   True to pop immediately, false otherwise.
 */
public static void popTo(@NonNull final FragmentManager fm,
                         final Class<? extends Fragment> popClz,
                         final boolean isIncludeSelf,
                         final boolean isImmediate) {
    if (isImmediate) {
        fm.popBackStackImmediate(popClz.getName(),
                isIncludeSelf ? FragmentManager.POP_BACK_STACK_INCLUSIVE : 0);
    } else {
        fm.popBackStack(popClz.getName(),
                isIncludeSelf ? FragmentManager.POP_BACK_STACK_INCLUSIVE : 0);
    }
}
 
Example 5
Source File: MainActivity.java    From Shield with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    FragmentManager fm = getSupportFragmentManager();
    if (fm.popBackStackImmediate()){// pop成功;
        getSupportActionBar().setTitle(R.string.app_name);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    } else {
        super.onBackPressed();
    }
}
 
Example 6
Source File: FragmentUtil.java    From DeviceInfo with Apache License 2.0 5 votes vote down vote up
public void clearBackStackFragmets(final String tag)
    {
        // in my case I get the support fragment manager, it should work with the native one too
        FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
        // this will clear the back stack and displays no animation on the screen
        fragmentManager.popBackStackImmediate(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        // fragmentManager.popBackStackImmediate(SplashFragment.class.getCanonicalName(),FragmentManager.POP_BACK_STACK_INCLUSIVE);

//        Methods.hideKeyboard();
    }
 
Example 7
Source File: RouteFragment.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
private void replaceFragment(int id, Fragment fragment) {
    FragmentManager fragmentManager = getChildFragmentManager();
    fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentManager.beginTransaction()
            .replace(id, fragment, fragment.getClass().getSimpleName())
            .commit();
}
 
Example 8
Source File: Wizard.java    From Wizard with Apache License 2.0 5 votes vote down vote up
public boolean returnToFirst() {
  if (!activity.isFinishing()) {
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
      String name = fragmentManager.getBackStackEntryAt(0).getName();
      fragmentManager.popBackStackImmediate(name, FragmentManager.POP_BACK_STACK_INCLUSIVE);
      return true;
    }
  }
  return false;
}
 
Example 9
Source File: SinglePaneActivity.java    From MongoExplorer with MIT License 5 votes vote down vote up
private void clearBackStack() {
	FragmentManager fm = getSupportFragmentManager();

	while (fm.getBackStackEntryCount() > 0) {
		fm.popBackStackImmediate();
	}
}
 
Example 10
Source File: BitBaseFragment.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 判断当前 Fragment 是否消费回退事件
 *
 * @param fragmentManager 上级fragment 的管理
 * @return
 */
public boolean onConsumeBackEvent(FragmentManager fragmentManager) {
    boolean consume = FragmentCompat.isConsumeBackEvent(getChildFragmentManager());
    if (consume) {
        // 子fragment消费成功以后,判断当前fragment是否还有子fragment,没有的话,看情况决定是否关闭
        if (getChildFragmentManager().getBackStackEntryCount() == 0 && noChild2Finish()) {
            return fragmentManager.popBackStackImmediate();
        }
        return true;
    } else {
        // 子fragment未消费回退事件,则由当前fragment进行消费
        return fragmentManager.popBackStackImmediate();
    }
}
 
Example 11
Source File: FragmentUtils.java    From Android-UtilCode with Apache License 2.0 4 votes vote down vote up
/**
 * 出栈同级别fragment
 *
 * @param fragmentManager fragment管理器
 */
public static void popFragments(@NonNull FragmentManager fragmentManager) {
    while (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStackImmediate();
    }
}
 
Example 12
Source File: SinglePaneActivity.java    From MongoExplorer with MIT License 4 votes vote down vote up
public void onEvent(Events.CollectionDropped e) {
	FragmentManager fm = getSupportFragmentManager();
	fm.popBackStackImmediate();
	CollectionListFragment fragment = (CollectionListFragment)fm.findFragmentById(R.id.frame_1);
	fragment.onEvent(e);
}
 
Example 13
Source File: FragmentUtils.java    From MVVMArms with Apache License 2.0 4 votes vote down vote up
/**
 * 出栈同级别fragment
 *
 * @param fragmentManager fragment管理器
 */
public static void popFragments(@NonNull FragmentManager fragmentManager) {
    while (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStackImmediate();
    }
}
 
Example 14
Source File: FragmentUtils.java    From TikTok with Apache License 2.0 2 votes vote down vote up
/**
 * 出栈到指定fragment
 *
 * @param fragmentManager fragment管理器
 * @param fragmentClass   Fragment类
 * @param isIncludeSelf   是否包括Fragment类自己
 * @return {@code true}: 出栈成功<br>{@code false}: 出栈失败
 */
public static boolean popToFragment(@NonNull FragmentManager fragmentManager,
                                    Class<? extends Fragment> fragmentClass,
                                    boolean isIncludeSelf) {
    return fragmentManager.popBackStackImmediate(fragmentClass.getSimpleName(), isIncludeSelf ? FragmentManager.POP_BACK_STACK_INCLUSIVE : 0);
}
 
Example 15
Source File: FragmentUtils.java    From Android-UtilCode with Apache License 2.0 2 votes vote down vote up
/**
 * 出栈fragment
 *
 * @param fragmentManager fragment管理器
 * @return {@code true}: 出栈成功<br>{@code false}: 出栈失败
 */
public static boolean popFragment(@NonNull FragmentManager fragmentManager) {
    return fragmentManager.popBackStackImmediate();
}
 
Example 16
Source File: FragmentUtils.java    From Android-UtilCode with Apache License 2.0 2 votes vote down vote up
/**
 * 出栈到指定fragment
 *
 * @param fragmentManager fragment管理器
 * @param fragmentClass   Fragment类
 * @param isIncludeSelf   是否包括Fragment类自己
 * @return {@code true}: 出栈成功<br>{@code false}: 出栈失败
 */
public static boolean popToFragment(@NonNull FragmentManager fragmentManager,
                                    Class<? extends Fragment> fragmentClass,
                                    boolean isIncludeSelf) {
    return fragmentManager.popBackStackImmediate(fragmentClass.getName(), isIncludeSelf ? FragmentManager.POP_BACK_STACK_INCLUSIVE : 0);
}
 
Example 17
Source File: FragmentUtils.java    From MVVMArms with Apache License 2.0 2 votes vote down vote up
/**
 * 出栈到指定fragment
 *
 * @param fragmentManager fragment管理器
 * @param fragmentClass   Fragment类
 * @param isIncludeSelf   是否包括Fragment类自己
 * @return {@code true}: 出栈成功<br>{@code false}: 出栈失败
 */
public static boolean popToFragment(@NonNull FragmentManager fragmentManager,
                                    Class<? extends Fragment> fragmentClass,
                                    boolean isIncludeSelf) {
    return fragmentManager.popBackStackImmediate(fragmentClass.getSimpleName(), isIncludeSelf ? FragmentManager.POP_BACK_STACK_INCLUSIVE : 0);
}
 
Example 18
Source File: FragmentUtils.java    From TikTok with Apache License 2.0 2 votes vote down vote up
/**
 * 出栈fragment
 *
 * @param fragmentManager fragment管理器
 * @return {@code true}: 出栈成功<br>{@code false}: 出栈失败
 */
public static boolean popFragment(@NonNull FragmentManager fragmentManager) {
    return fragmentManager.popBackStackImmediate();
}
 
Example 19
Source File: FragmentUtils.java    From styT with Apache License 2.0 2 votes vote down vote up
/**
 * 出栈到指定fragment
 *
 * @param fragmentManager fragment管理器
 * @param fragmentClass   Fragment类
 * @param isIncludeSelf   是否包括Fragment类自己
 * @return {@code true}: 出栈成功<br>{@code false}: 出栈失败
 */
public static boolean popToFragment(@NonNull final FragmentManager fragmentManager,
                                    final Class<? extends Fragment> fragmentClass,
                                    final boolean isIncludeSelf) {
    return fragmentManager.popBackStackImmediate(fragmentClass.getName(), isIncludeSelf ? FragmentManager.POP_BACK_STACK_INCLUSIVE : 0);
}
 
Example 20
Source File: FragmentUtils.java    From styT with Apache License 2.0 2 votes vote down vote up
/**
 * 出栈fragment
 *
 * @param fragmentManager fragment管理器
 * @return {@code true}: 出栈成功<br>{@code false}: 出栈失败
 */
public static boolean popFragment(@NonNull final FragmentManager fragmentManager) {
    return fragmentManager.popBackStackImmediate();
}