Example usage for android.support.v4.app FragmentManager popBackStack

List of usage examples for android.support.v4.app FragmentManager popBackStack

Introduction

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

Prototype

public abstract void popBackStack();

Source Link

Document

Pop the top state off the back stack.

Usage

From source file:com.nanostuffs.yurdriver.fragment.RegisterFragment.java

private void actionBarDetails() {
    getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    final View addView = getActivity().getLayoutInflater().inflate(R.layout.my_custom_navigation, null);

    TextView title = (TextView) addView.findViewById(R.id.title);
    title.setText("REGISTRATION");
    ImageView back = (ImageView) addView.findViewById(R.id.back);
    back.setOnClickListener(new OnClickListener() {

        @Override// w  w w .  j  a  v  a  2  s .co  m
        public void onClick(View v) {
            // TODO Auto-generated method stub
            FragmentManager manager = getActivity().getSupportFragmentManager();
            manager.popBackStack();

        }
    });
    getActivity().getActionBar().setCustomView(addView);
}

From source file:ru.orangesoftware.financisto.activity.MainActivity.java

@Override
public void onBackPressed() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 1) {
        fragmentManager.popBackStack();
        mDrawerLayout.closeDrawers();/*from  www .  j a  v a2  s  .c  om*/
    } else {
        finishAfterTransition();
    }
}

From source file:com.recurly.androidsdk.BaseActivity.java

protected void popFragment() {
    FragmentManager fragmentManager = getSupportFragmentManager();

    int backStackEntryCount = fragmentManager.getBackStackEntryCount();

    if (backStackEntryCount >= 1) {
        // remove existing fragment
        fragmentManager.executePendingTransactions();

        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        BaseFragment currentFragment = (BaseFragment) fragmentManager
                .findFragmentByTag("" + fragmentManager.getBackStackEntryCount());

        BaseFragment nextFragment = (BaseFragment) fragmentManager
                .findFragmentByTag("" + (fragmentManager.getBackStackEntryCount() - 1));

        if (nextFragment == null) {
            // no more fragments, so exit
            finish();//from www.  j  a v  a  2 s .  c  om
            return;
        }

        fragmentTransaction.remove(currentFragment);

        fragmentTransaction.show(nextFragment);

        fragmentManager.popBackStack();

        fragmentTransaction.commit();

    } else {
        // going to exit..
        super.onBackPressed();
    }
}

From source file:com.supremainc.biostar2.main.HomeActivity.java

/**
 * 1 depth menu???. stack??? clear/*w ww  .j av a  2s . c o m*/
 *
 * @param type
 * @param args
 */
public void gotoScreen(ScreenType type, Bundle args, boolean skipAni) {
    if (type == null) {
        return;
    }

    if (activityScreen(type, args)) {
        return;
    }

    switch (type) {
    case LOG_OUT:
        logOut();
        return;
    case OPEN_MENU:
        mLayout.onDrawMenu();
        return;
    default:
        break;
    }

    BaseFragment fragment = createFragement(type, args);
    if (fragment == null) {
        if (BuildConfig.DEBUG) {
            Log.e(TAG, "fragment null gotoScreen:" + type);
        }
        mLayout.closeDrawer();
        return;
    }
    mFragment = fragment;

    if (BuildConfig.DEBUG) {
        Log.i(TAG, "gotoScreen:" + type);
    }

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

    FragmentTransaction transaction = fm.beginTransaction();
    if (!skipAni) {
        if (type == ScreenType.MAIN) {
            transaction.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right);
        } else {
            transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left,
                    R.anim.enter_from_left, R.anim.exit_to_right);
        }
    }
    transaction.replace(R.id.content_frame, mFragment);
    transaction.commitAllowingStateLoss();
    if (type != ScreenType.MAIN) {
        mHandler.postDelayed(mCloseDrawer, 200);
    }
}

From source file:com.nadmm.airports.ActivityBase.java

@Override
public void onBackPressed() {
    // If the drawer is open, back will close it
    if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawers();//from  w w  w  .  j  a v  a  2 s . c om
        return;
    }
    // Otherwise, it may return to the previous fragment stack
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
    } else {
        // Lastly, it will rely on the system behavior for back
        super.onBackPressed();
    }
}

From source file:com.androzic.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action buttons
    switch (item.getItemId()) {
    case android.R.id.home:
        FragmentManager fm = getSupportFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            View v = getCurrentFocus();
            if (v != null) {
                // Hide keyboard
                final InputMethodManager imm = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }/*from www .  j  a  va  2s.c  o m*/
            fm.popBackStack();
            return true;
        } else {
            if (mDrawerToggle.onOptionsItemSelected(item)) {
                return true;
            }
        }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:ru.sawimmod.activities.SawimActivity.java

@Override
public void onResume() {
    super.onResume();
    SawimApplication.maximize();/*from ww  w . ja  v  a 2  s. co  m*/
    FragmentManager fragmentManager = getSupportFragmentManager();
    StartWindowView startWindowView = (StartWindowView) fragmentManager.findFragmentByTag(StartWindowView.TAG);
    if (RosterHelper.getInstance().getProtocolCount() == 0) {
        if (Options.getAccountCount() == 0) {
            FragmentTransaction transaction = fragmentManager.beginTransaction();
            if (SawimApplication.isManyPane()) {
                setContentView(R.layout.main);
                if (startWindowView == null) {
                    StartWindowView newFragment = new StartWindowView();
                    transaction.replace(R.id.fragment_container, newFragment, StartWindowView.TAG);
                    transaction.commit();
                    supportInvalidateOptionsMenu();
                }
            }
        } else {
            startActivity(new Intent(this, AccountsListActivity.class));
        }
    } else {
        if (startWindowView != null)
            fragmentManager.popBackStack();
    }
    try {
        handleIntent();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (!isOpenNewChat && SawimApplication.isManyPane())
        try {
            openChat(null, null, true);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
}

From source file:com.inter.trade.ui.fragment.agent.AgentApplyFragmentNew.java

/**
 * /*w ww.  j a v  a  2 s.  c o  m*/
 */
protected void setAgentBackVisible() {
    if (getActivity() == null) {
        return;
    }
    back = (Button) getActivity().findViewById(R.id.title_back_btn);

    if (back == null) {
        return;
    }
    back.setVisibility(View.VISIBLE);
    back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            FragmentManager manager = getActivity().getSupportFragmentManager();
            int len = manager.getBackStackEntryCount();
            if (len > 0) {
                manager.popBackStack();
            } else {
                getActivity().finish();
            }
        }
    });

    menu = (Button) getActivity().findViewById(R.id.title_menu_btn);
    menu.setVisibility(View.GONE);
    Button right = (Button) getActivity().findViewById(R.id.title_right_btn);
    right.setVisibility(View.GONE);
}

From source file:org.deviceconnect.android.manager.accesslog.AccessLogActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        callFragment();/*from  w w w. ja  va2 s.  c  om*/
        FragmentManager manager = getSupportFragmentManager();
        if (manager.getBackStackEntryCount() > 0) {
            manager.popBackStack();
        } else {
            finish();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.github.nicktgn.mvp_sample.ui.NotebookActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        FragmentManager fm = getSupportFragmentManager();

        // no more fragments in back stack -> go to parent activity
        if (fm.getBackStackEntryCount() == 0) {
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                logger.d("Creating NEW TASK...");
                // This activity is NOT part of this app's task, so create a new task
                // when navigating up, with a synthesized back stack.
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                        // Navigate up to the closest parent
                        .startActivities();
            } else {
                logger.d("Using SAME TASK...");
                // This activity is part of this app's task, so simply
                // navigate up to the logical parent activity.
                //NavUtils.navigateUpTo(this, upIntent);
                onBackPressed();//from ww w .j  a  v a2 s.co  m
            }
        }
        // still has fragments in back stack -> pop to previous fragment
        else {
            fm.popBackStack();
        }

        return true;
    }
    return super.onOptionsItemSelected(item);
}