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.sage42.androidappaddicts.app.main.MainActivity.java

/**
 * Show the previous fragment which is stored in the fragment transaction.
 * /*from   www.  j ava 2 s. c  o  m*/
 * @return
 */
protected boolean getAvailableBackStack() {
    final FragmentManager fragmentManager = this.getFragmentManager();

    // check the fragmentManager and show the previous fragment

    if (fragmentManager.getBackStackEntryCount() != 0) {
        fragmentManager.popBackStack();

        this.getActionBar().setDisplayHomeAsUpEnabled(true);

        if (fragmentManager.getBackStackEntryCount() == 1) {
            this.mDrawerToggle.syncState();
        }
        return true;
    }

    return false;
}

From source file:com.pepabo.jodo.jodoroid.MainActivity.java

@Override
public void onBackPressed() {
    if (mDrawerLayout.isDrawerOpen(mDrawer)) {
        mDrawerLayout.closeDrawer(mDrawer);
        return;/*from  www .j a va  2s . com*/
    }

    final FragmentManager fragmentManager = getFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 1) {
        fragmentManager.popBackStack();
        return;
    }

    super.onBackPressed();
}

From source file:us.cboyd.android.dicom.DcmBrowser.java

@Override
public void onBackPressed() {
    File temp = mListFragment.getDir();
    if (!mListFragment.isVisible()) {
        // Assume we're jumping back to the ListFragment
        if (ExternalIO.isRoot(temp)) {
            ActionBar actionBar = getActionBar();
            actionBar.setHomeButtonEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
        }/* w  ww.  j  a v a 2 s .c om*/
        FragmentManager fm = getFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
        } else {
            super.onBackPressed();
        }

        // If the directory is the external storage directory or there is no parent,
        // super.onBackPressed(). Else go to parent directory.
    } else if (ExternalIO.isRoot(temp)) {
        super.onBackPressed();
    } else {
        temp = temp.getParentFile();
        mListFragment.setDir(temp);
    }
    onDirectorySelected(temp);
}

From source file:com.murati.oszk.audiobook.ui.ActionBarCastActivity.java

@Override
public void onBackPressed() {
    // If the drawer is open, back will close it
    if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawers();/*w  w  w.  j a  va  2s . c  o m*/
        return;
    }

    String mediaId = null;
    if (this.getClass() == MusicPlayerActivity.class) {
        MusicPlayerActivity musicPlayerActivity = (MusicPlayerActivity) this;
        mediaId = musicPlayerActivity.getMediaId();
        if (mediaId != null && mediaId.startsWith(MediaIDHelper.MEDIA_ID_BY_SEARCH)) {
            Intent home = new Intent(ActionBarCastActivity.this, MusicPlayerActivity.class);
            home.setAction(Intent.ACTION_VIEW);
            home.putExtra(MediaIDHelper.EXTRA_MEDIA_ID_KEY, MediaIDHelper.MEDIA_ID_ROOT);
            startActivity(home);
            return;
        }
    }

    // Otherwise, it may return to the previous fragment stack
    FragmentManager fragmentManager = getFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
    } else {
        // Lastly, it will rely on the system behavior for back
        super.onBackPressed();
    }
}

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();/*  w  ww .ja v a 2 s .c  om*/
    } 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:com.ternup.caddisfly.fragment.ResultFragment.java

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {//www  . j  a  v  a 2s . 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.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();// w  w w  . j a  v  a  2 s.c om
    } else {
        super.onBackPressed();
    }
}

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

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {//w  w w .jav a  2 s. c om
        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.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;
            }//w w w. j a  va  2 s  . co m
        }
    }
    return super.onKeyUp(keyCode, event);
}

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

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

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