Example usage for android.app FragmentManager popBackStack

List of usage examples for android.app FragmentManager popBackStack

Introduction

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

Prototype

public abstract void popBackStack();

Source Link

Document

Pop the top state off the back stack.

Usage

From source file:com.ternup.caddisfly.fragment.ResultFragment.java

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {//w  w w  .ja  va2s. co m
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            fm.executePendingTransactions();
        } else {
            Fragment fragment = new HomeFragment();
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.executePendingTransactions();
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.replace(R.id.container, fragment, "0");
            ft.addToBackStack(null);
            ft.commit();
            fm.executePendingTransactions();
            ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer);
            drawerList.setItemChecked(0, true);
            drawerList.setSelection(0);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ternup.caddisfly.fragment.DetailsFragment.java

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {/*  ww w  . ja v  a  2 s.co m*/
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            fm.executePendingTransactions();
        } else {
            Fragment fragment = new HomeFragment();
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.replace(R.id.container, fragment, "0");
            ft.addToBackStack(null);
            ft.commit();
            fm.executePendingTransactions();
            ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer);
            drawerList.setItemChecked(0, true);
            drawerList.setSelection(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.avapira.bobroreader.Bober.java

@Override
public void onBackPressed() {
    //handle the back press :D close the drawer first and if the drawer is closed close the activity
    if (boardsDrawer != null && boardsDrawer.isDrawerOpen()) {
        boardsDrawer.closeDrawer();/*from   w ww. jav a2s.c o m*/
    } else {
        FragmentManager fm = getFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            Log.i("Bober", "popping backstack");
            fm.popBackStack();
        } else {
            Log.i("Bober", "nothing on backstack, calling super");
            super.onBackPressed();
        }
    }
}

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();
}

From source file:com.serenegiant.aceparrot.AbstractMainActivity.java

@Override
public void onBackPressed() {
    //ActionBarActivity/AppCompatActivity???????????
    // ????????????workaround
    final FragmentManager fm = getFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        if (DEBUG)
            Log.i(TAG, "#onBackPressed:popBackStack");
        fm.popBackStack();
    } else {/*from  ww  w .  j a va 2  s .co m*/
        super.onBackPressed();
    }
}

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

private void selectMenuItem(int position) {
    if (prevSelection == position && position != 0)
        return;//from w  w  w  .ja v  a  2 s  .co m

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

    Bundle args = new Bundle();
    if (position == 0 || position == 2 || position == 3)
        curFragment = new PostsRecyclerFragment();

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

    prevSelection = (byte) position;

    switch (position) {
    case 2:
        args.putString(Constants.KEY_TYPE, Constants.RECENSIONI);
        break;
    case 3:
        args.putString(Constants.KEY_TYPE, Constants.VIDEO);
        break;
    case 4:
        curFragment = new ProductsListFragment();
        break;
    }

    if (position != 1) {
        if (position != 4)
            curFragment.setArguments(args);
        ft.replace(R.id.content_frame, curFragment);
    }
    ft.commit();
    setToolbarStatusColor(-1);
}

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

private void selectCategoryItem(int position) {
    if (prevChildSelection == position)
        return;/*from   ww w  .  ja v  a  2s. c  o  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.lgallardo.youtorrentcontroller.ItemstFragment.java

private void newDetailsFragment(int position) {

    detailsFragment = new TorrentDetailsFragment();

    // Get torrent from MainActivity
    detailsFragment.setTorrent(MainActivity.lines[position]);

    detailsFragment.setPosition(position);

    if (detailsFragment != null) {
        FragmentManager fragmentManager = getFragmentManager();

        if (getActivity().findViewById(R.id.one_frame) != null) {
            fragmentManager.beginTransaction()
                    .replace(this.getSecondFragmentContainer(), detailsFragment, "firstFragment")
                    .addToBackStack("secondFragment").commit();

            // Change toolbar home button behaviour
            originalListener = MainActivity.drawerToggle.getToolbarNavigationClickListener();

            MainActivity.drawerToggle.setDrawerIndicatorEnabled(false);
            MainActivity.drawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer);
            MainActivity.drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
                @Override// www .  jav a 2 s.  co m
                public void onClick(View v) {

                    // Disable refreshing
                    MainActivity.disableRefreshSwipeLayout();

                    // Set default toolbar behaviour
                    ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(true);
                    MainActivity.drawerToggle.setDrawerIndicatorEnabled(true);
                    MainActivity.drawerToggle.setToolbarNavigationClickListener(originalListener);
                    ((MainActivity) getActivity()).setSelectionAndTitle(MainActivity.currentState);

                    // Show herderInfo in phone's view
                    if (getActivity().findViewById(R.id.one_frame) != null) {

                        if (MainActivity.headerInfo != null) {
                            if (MainActivity.header) {
                                MainActivity.headerInfo.setVisibility(View.VISIBLE);
                            } else {
                                MainActivity.headerInfo.setVisibility(View.GONE);
                            }
                        }

                    }

                    FragmentManager fm = getFragmentManager();
                    fm.popBackStack();

                }
            });
        } else {
            fragmentManager.beginTransaction()
                    .replace(this.getSecondFragmentContainer(), detailsFragment, "secondFragment")
                    .addToBackStack("secondFragment").commit();
        }
    }

}

From source file:by.zatta.pilight.MainActivity.java

@Override
public void onLanguageListener(String language) {
    makeLocale(language);/*from   w  ww . j a  v a  2  s. c  o m*/
    invalidateOptionsMenu();
    initMenu();
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    fm.popBackStack();
    ft.replace(R.id.fragment_main, new PrefFragment(), "prefs");
    ft.addToBackStack(null);
    ft.commit();
}

From source file:by.zatta.pilight.MainActivity.java

private void openFragment(BaseFragment mBaseFragment2) {
    Log.v(TAG, "openFragment");
    if (mBaseFragment2 != null) {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        fm.popBackStack();
        ft.replace(R.id.fragment_main, mBaseFragment2, mBaseFragment2.getName());
        ft.commit();//  www.  j  a  va2s.c o m
    }
}