List of usage examples for android.app FragmentManager popBackStack
public abstract void popBackStack(int id, int flags);
From source file:com.QuarkLabs.BTCeClient.MainActivity.java
/** * Displays selected fragment//from w w w .ja v a2 s .co m * * @param position Position at the list (0-based) */ private void displayItem(final int position) { Fragment fragment = null; final FragmentManager fragmentManager = getFragmentManager(); switch (position) { case 0: fragment = mHomeFragment; fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); break; case 1: fragment = new OrdersBookFragment(); break; case 2: fragment = new ActiveOrdersFragment(); break; case 3: fragment = HistoryFragment.newInstance(ListType.Trades); break; case 4: fragment = HistoryFragment.newInstance(ListType.Transactions); break; case 5: fragment = new ChartsFragment(); break; case 6: fragment = new SettingsFragment(); break; case 7: fragment = new NotifiersFragment(); break; case 8: fragment = new HelpFragment(); break; default: break; } final Fragment fr = fragment; if (fr != null) { //delay in msecs int delay = 250; //post delayed for smooth behaviour new Handler().postDelayed(new Runnable() { @Override public void run() { FragmentTransaction transaction = fragmentManager.beginTransaction() .setCustomAnimations(R.animator.fade_in, R.animator.fade_out) .replace(R.id.content_frame, fr); if (position != 0) { transaction.addToBackStack(String.valueOf(position)); //name of fragment = position } transaction.commit(); setTitle(mDrawerListItems[position]); } }, delay); mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); if (mDrawerLayout != null) { mDrawerLayout.closeDrawer(mDrawerList); } } }
From source file:com.sage42.androidappaddicts.app.main.MainActivity.java
/** * Remove all back stack to avoid missing flow on back pressed. *//* w w w. j a v a2s .co 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:com.bradbergeron.splitviewcontrollerdemo.activities.MainActivity.java
@Override public void onDrawerItemSelected(final DrawerFragment.FragmentDrawerItem fragmentDrawerItem) { if (mDrawerLayout.isDrawerOpen(Gravity.START)) { mDrawerLayout.closeDrawer(Gravity.START); }// w ww. j a va2 s . com 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: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 ww w. j ava 2s.com*/ } } return super.onKeyUp(keyCode, event); }
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 w w w . ja v a2 s .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 w w .j a va 2s. 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 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}. *//* ww w .j a v a 2 s. c o m*/ 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; } } } }
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 2 s.co 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()); }
From source file:de.sourcestream.movieDB.MainActivity.java
/** * Displays fragment view for the selected item from the slide menu. * * @param position is the position that we have selected. *//*from ww w .j av a 2 s . c o m*/ private void displayView(int position) { if (position != 0) { // Clear history of the back stack if any FragmentManager fm = getFragmentManager(); fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // update the main content by replacing fragments Fragment fragment = null; searchMovieDetails = 0; searchCastDetails = 0; searchTvDetails = 0; searchViewCount = false; resetMovieDetailsBundle(); resetCastDetailsBundle(); resetTvDetailsBundle(); switch (position) { // Case 0 is the header we don't want to do anything with it. case 1: reAttachMovieFragments = true; if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = movieSlideTab; break; case 2: reAttachTVFragments = true; if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = tvSlideTab; break; case 3: if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = getFragmentManager().findFragmentByTag("genres"); if (fragment == null) fragment = genresList; if (genresList.getBackState() == 0) genresList.updateList(); break; case 4: if (oldPos == position) { mDrawerLayout.closeDrawer(mDrawerList); break; } fragment = about; break; default: break; } oldPos = position; if (fragment != null) { fm.beginTransaction().replace(R.id.frame_container, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); setTitle(navMenuTitles[position - 1]); mDrawerLayout.closeDrawer(mDrawerList); try { movieSlideTab.showInstantToolbar(); tvSlideTab.showInstantToolbar(); } catch (NullPointerException e) { } System.gc(); } } else { mDrawerList.setItemChecked(oldPos, true); } }