Example usage for android.app FragmentManager getBackStackEntryAt

List of usage examples for android.app FragmentManager getBackStackEntryAt

Introduction

In this page you can find the example usage for android.app FragmentManager getBackStackEntryAt.

Prototype

public abstract BackStackEntry getBackStackEntryAt(int index);

Source Link

Document

Return the BackStackEntry at index index in the back stack; where the item on the bottom of the stack has index 0.

Usage

From source file:com.QuarkLabs.BTCeClient.MainActivity.java

@Override
public void onBackPressed() {
    super.onBackPressed();
    int switchToPosition = 0;
    FragmentManager fm = getFragmentManager();
    if (fm.getBackStackEntryCount() != 0) {
        String stackName = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName();
        switchToPosition = Integer.parseInt(stackName);
    }//w  w w .  java 2s  .co m
    mDrawerList.setItemChecked(switchToPosition, true);
    mDrawerList.setSelection(switchToPosition);
    setTitle(mDrawerListItems[switchToPosition]);
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java

private void popBackStack() {
    final FragmentManager fragmentManager = getFragmentManager();
    final int backStackEntryCount = fragmentManager.getBackStackEntryCount();
    final FragmentManager.BackStackEntry previousFragment = fragmentManager
            .getBackStackEntryAt(backStackEntryCount - 2);
    final String previousFragmentActionBarTitle = previousFragment.getName();
    setActionBarTitle(previousFragmentActionBarTitle);
    fragmentManager.popBackStack();/*w ww .ja v a  2 s  . com*/
}

From source file:com.sage42.androidappaddicts.app.main.MainActivity.java

/**
 * Remove all back stack to avoid missing flow on back pressed.
 *//*from  www  .  j a va 2  s  . c o  m*/
private void clearAllBackStack() {
    final FragmentManager fragmentManager = this.getFragmentManager();

    final int backStackCount = fragmentManager.getBackStackEntryCount();
    for (int i = 0; i < backStackCount; i++) {
        // removing all the stored backstack
        final int backStackId = fragmentManager.getBackStackEntryAt(i).getId();
        fragmentManager.popBackStack(backStackId, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

}

From source file:de.jadehs.jadehsnavigator.MainActivity.java

@Override
public void onBackPressed() {
    FragmentManager fragmentManager = getFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 1) {
        // jump to previous fragment
        fragmentManager.popBackStackImmediate();
        FragmentManager.BackStackEntry entry = fragmentManager
                .getBackStackEntryAt(fragmentManager.getBackStackEntryCount() - 1);
        setTitle(entry.getName());/*from   ww  w .java2s  .  c  o m*/
    } else {
        // quit the app
        super.onBackPressed();
    }
}

From source file:com.android.tv.tuner.setup.TunerSetupActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        FragmentManager manager = getFragmentManager();
        int count = manager.getBackStackEntryCount();
        if (count > 0) {
            String lastTag = manager.getBackStackEntryAt(count - 1).getName();
            if (ScanResultFragment.class.getCanonicalName().equals(lastTag) && count >= 2) {
                // Pops fragment including ScanFragment.
                manager.popBackStack(manager.getBackStackEntryAt(count - 2).getName(),
                        FragmentManager.POP_BACK_STACK_INCLUSIVE);
                return true;
            } else if (ScanFragment.class.getCanonicalName().equals(lastTag)) {
                mLastScanFragment.finishScan(true);
                return true;
            }/*from   w w  w. j a  va 2s  .co  m*/
        }
    }
    return super.onKeyUp(keyCode, event);
}

From source file:cx.ring.client.HomeActivity.java

private void popCustomBackStack() {
    FragmentManager fm = getFragmentManager();
    FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt(0);
    fContent = fm.findFragmentByTag(entry.getName());
    for (int i = 0; i < fm.getBackStackEntryCount() - 1; ++i) {
        fm.popBackStack();//w ww .  j  a v a 2s  . c  o m
    }
}

From source file:org.naturenet.ui.MainActivity.java

private void clearBackStack() {
    FragmentManager manager = getFragmentManager();
    if (manager.getBackStackEntryCount() > 0) {
        FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
        manager.popBackStack(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }//from   www  .  j  ava 2s .  c  o m
}

From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java

/**
 * Convenient method to close GuidedStepListFragments on top of other content or finish Activity if
 * GuidedStepListFragments were started in a separate activity.  Pops all stack entries including
 * {@link #UI_STYLE_ENTRANCE}; if {@link #UI_STYLE_ENTRANCE} is not found, finish the activity.
 * Note that this method must be paired with {@link #add(FragmentManager, GuidedStepListFragment,
 * int)} which sets up the stack entry name for finding which fragment we need to pop back to.
 *///from  w ww  . j  av  a2 s .  c o m
public void finishGuidedStepListFragments() {
    final FragmentManager fragmentManager = getFragmentManager();
    final int entryCount = fragmentManager.getBackStackEntryCount();
    if (entryCount > 0) {
        for (int i = entryCount - 1; i >= 0; i--) {
            FragmentManager.BackStackEntry entry = fragmentManager.getBackStackEntryAt(i);
            if (isStackEntryUiStyleEntrance(entry.getName())) {
                GuidedStepListFragment top = getCurrentGuidedStepListFragment(fragmentManager);
                if (top != null) {
                    top.setUiStyle(UI_STYLE_ENTRANCE);
                }
                fragmentManager.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
                return;
            }
        }
    }
    ActivityCompat.finishAfterTransition(getActivity());
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

/**
 * Convenient method to close GuidedStepFragments on top of other content or finish Activity if
 * GuidedStepFragments were started in a separate activity.  Pops all stack entries including
 * {@link #UI_STYLE_ENTRANCE}; if {@link #UI_STYLE_ENTRANCE} is not found, finish the activity.
 * Note that this method must be paired with {@link #add(FragmentManager, GuidedStepFragment,
 * int)} which sets up the stack entry name for finding which fragment we need to pop back to.
 *///from  w w w  .ja  v  a 2s .  c om
public void finishGuidedStepFragments() {
    final FragmentManager fragmentManager = getFragmentManager();
    final int entryCount = fragmentManager.getBackStackEntryCount();
    if (entryCount > 0) {
        for (int i = entryCount - 1; i >= 0; i--) {
            BackStackEntry entry = fragmentManager.getBackStackEntryAt(i);
            if (isStackEntryUiStyleEntrance(entry.getName())) {
                GuidedStepFragment top = getCurrentGuidedStepFragment(fragmentManager);
                if (top != null) {
                    top.setUiStyle(UI_STYLE_ENTRANCE);
                }
                fragmentManager.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
                return;
            }
        }
    }
    ActivityCompat.finishAfterTransition(getActivity());
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

/**
 * Convenient method to pop to fragment with Given class.
 * @param  guidedStepFragmentClass  Name of the Class of GuidedStepFragment to pop to.
 * @param flags Either 0 or {@link FragmentManager#POP_BACK_STACK_INCLUSIVE}.
 *///from  w  w  w.ja  v  a2s.  c om
public void popBackStackToGuidedStepFragment(Class guidedStepFragmentClass, int flags) {
    if (!GuidedStepFragment.class.isAssignableFrom(guidedStepFragmentClass)) {
        return;
    }
    final FragmentManager fragmentManager = getFragmentManager();
    final int entryCount = fragmentManager.getBackStackEntryCount();
    String className = guidedStepFragmentClass.getName();
    if (entryCount > 0) {
        for (int i = entryCount - 1; i >= 0; i--) {
            BackStackEntry entry = fragmentManager.getBackStackEntryAt(i);
            String entryClassName = getGuidedStepFragmentClassName(entry.getName());
            if (className.equals(entryClassName)) {
                fragmentManager.popBackStack(entry.getId(), flags);
                return;
            }
        }
    }
}