Example usage for android.app FragmentManager getBackStackEntryCount

List of usage examples for android.app FragmentManager getBackStackEntryCount

Introduction

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

Prototype

public abstract int getBackStackEntryCount();

Source Link

Document

Return the number of entries currently in the back stack.

Usage

From source file:com.near.chimerarevo.activities.MainActivity.java

private void selectCategoryItem(int position) {
    if (prevChildSelection == position)
        return;/*from ww w.j a  v a 2  s  .  co  m*/

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    Bundle args = new Bundle();
    curFragment = new PostsRecyclerFragment();

    FragmentManager fm = getFragmentManager();
    for (int i = 0; i < fm.getBackStackEntryCount(); ++i) {
        fm.popBackStack();
    }

    prevChildSelection = (byte) position;

    switch (position) {
    case 0:
        args.putString(Constants.KEY_CAT, Constants.ANDROID);
        break;
    case 1:
        args.putString(Constants.KEY_CAT, Constants.APPLE);
        break;
    case 2:
        args.putString(Constants.KEY_CAT, Constants.GIOCHI);
        break;
    case 3:
        args.putString(Constants.KEY_CAT, Constants.HARDWARE);
        break;
    case 4:
        args.putString(Constants.KEY_CAT, Constants.INTERNET);
        break;
    case 5:
        args.putString(Constants.KEY_CAT, Constants.LINUX);
        break;
    case 6:
        args.putString(Constants.KEY_CAT, Constants.SMARTPHONE);
        break;
    case 7:
        args.putString(Constants.KEY_CAT, Constants.TABLET);
        break;
    case 8:
        args.putString(Constants.KEY_CAT, Constants.WINDOWS);
        break;
    default:
        break;
    }

    curFragment.setArguments(args);
    ft.replace(R.id.content_frame, curFragment);
    ft.commit();
    setToolbarStatusColor(position);
}

From source file:com.bradbergeron.splitviewcontrollerdemo.activities.MainActivity.java

@Override
public void onDrawerItemSelected(final DrawerFragment.FragmentDrawerItem fragmentDrawerItem) {
    if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
        mDrawerLayout.closeDrawer(Gravity.START);
    }/*from  w ww . j  a  va 2s.c om*/

    final FragmentManager fragmentManager = getFragmentManager();
    final String fragmentClassName = fragmentDrawerItem.getFragmentClass().getName();

    Fragment newFragment = fragmentManager.findFragmentByTag(fragmentClassName);

    if (newFragment == null) {
        newFragment = Fragment.instantiate(this, fragmentClassName);
    } else if (newFragment.isAdded()) {
        return;
    } else if (fragmentDrawerItem.isDefaultItem() && fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack("Drawer", FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.content, newFragment, fragmentClassName);

    if (!fragmentDrawerItem.isDefaultItem()) {
        transaction.addToBackStack("Drawer");
    }

    transaction.commit();
}

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.  jav  a  2 s.  com
    }
}

From source file:eu.focusnet.app.ui.activity.ProjectsListingActivity.java

/**
 * Listener for the back button. We have 2 menu entries in the drawer menu that load their
 * fragment in the main content container.
 * <p/>//from  w  ww .  j  a va 2s. c  o  m
 * In {@link #getOnClickDrawerItemListener()}, we make sure we do not reload the same page
 * indefinitely such that the below logic can work.
 */
@Override
public void onBackPressed() {
    //Navigate back to the last Fragment or exit the application
    FragmentManager fragmentManager = getFragmentManager();
    // If we have more than one fragments in the stack remove the last inserted
    // This is the case where we move from Bookmarks back to the home page via the BACK button
    if (fragmentManager.getBackStackEntryCount() > 1) {
        //remove the last inserted fragment from the stack
        fragmentManager.popBackStackImmediate();

        // hard coded things is ok as we are only playing with 2 possible targets, and
        // hence hitting the BACK button will always make us go back to the home page
        // (if we hit the BACK button on the home page, we exit the app)
        this.actionBar.setTitle(R.string.project_listing_title);
        highlightSelectedMenuItem(Constant.Navigation.UI_MENU_ENTRY_PROJECTS_LISTING);

        // close the drawer
        this.drawerLayout.closeDrawer(this.drawerListMenu);
    } else {
        // Exit the application
        super.onBackPressed();
    }
}

From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java

@Override
public void onBackPressed() {
    //Pop any Fragments if they exist in the navigation stack.
    final FragmentManager manager = getFragmentManager();
    if (manager.getBackStackEntryCount() > 0) {
        manager.popBackStackImmediate();
        return;//from  w ww .  j  a v a  2s  .  co m
    }
    super.onBackPressed();
}

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);
    }/*  w  w  w. j av a2s .  com*/
}

From source file:com.android.tv.ui.TvOverlayManager.java

private void runAfterSideFragmentsAreClosed(final Runnable runnable) {
    final FragmentManager manager = mMainActivity.getFragmentManager();
    if (mSideFragmentManager.isSidePanelVisible()) {
        manager.addOnBackStackChangedListener(new OnBackStackChangedListener() {
            @Override//from w w w .  java 2s  .  c  o  m
            public void onBackStackChanged() {
                if (manager.getBackStackEntryCount() == 0) {
                    manager.removeOnBackStackChangedListener(this);
                    runnable.run();
                }
            }
        });
    } else {
        runnable.run();
    }
}

From source file:org.symptomcheck.capstone.ui.MainActivityOld.java

@Override
public void onBackPressed() {

    if (mFabActionsMenu.isExpanded()) {
        mFabActionsMenu.collapse();//  w w w.j  a v  a  2 s  .  co m
    } else {
        // initialize variables
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();

        // check to see if stack is empty
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            ft.commit();
            //            } else {
            //                askForExit();
        } else {
            if (mDoubleBackToExitPressedOnce) {
                super.onBackPressed();
                return;
            }
            this.mDoubleBackToExitPressedOnce = true;
            Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();

            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mDoubleBackToExitPressedOnce = false;
                }
            }, 2000);
        }
    }
}

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.
 *///  w w w .  java2 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.
 *//* w ww .  ja va2s .c o m*/
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());
}