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

The following examples show how to use android.support.v4.app.FragmentManager#getBackStackEntryAt() . 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 openshop.io-android with MIT License 6 votes vote down vote up
/**
     * Method clear fragment backStack (back history). On bottom of stack will remain Fragment added by {@link #addInitialFragment()}.
     */
    private void clearBackStack() {
        Timber.d("Clearing backStack");
        FragmentManager manager = getSupportFragmentManager();
        if (manager.getBackStackEntryCount() > 0) {
            if (BuildConfig.DEBUG) {
                for (int i = 0; i < manager.getBackStackEntryCount(); i++) {
                    Timber.d("BackStack content_%d= id: %d, name: %s", i, manager.getBackStackEntryAt(i).getId(), manager.getBackStackEntryAt(i).getName());
                }
            }
            FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
            manager.popBackStackImmediate(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
        Timber.d("backStack cleared.");
//        TODO maybe implement own fragment backStack handling to prevent banner fragment recreation during clearing.
//        http://stackoverflow.com/questions/12529499/problems-with-android-fragment-back-stack
    }
 
Example 2
Source File: MainActivity.java    From Androzic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addFragment(Fragment fragment, String tag)
{
	FragmentManager fm = getSupportFragmentManager();
	// Get topmost fragment
	Fragment parent;
	if (fm.getBackStackEntryCount() > 0)
	{
		FragmentManager.BackStackEntry bse = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1);
		parent = fm.findFragmentByTag(bse.getName());
	}
	else
	{
		parent = fm.findFragmentById(R.id.content_frame);
	}
	FragmentTransaction ft = fm.beginTransaction();
	// Detach parent
	ft.detach(parent);
	// Add new fragment to back stack
	ft.add(R.id.content_frame, fragment, tag);
	ft.addToBackStack(tag);
	ft.commit();
}
 
Example 3
Source File: FragmentUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Pop all fragments.
 *
 * @param fm The manager of fragment.
 */
public static void popAll(@NonNull final FragmentManager fm, final boolean isImmediate) {
    if (fm.getBackStackEntryCount() > 0) {
        FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt(0);
        if (isImmediate) {
            fm.popBackStackImmediate(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        } else {
            fm.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    }
}