Example usage for android.app FragmentTransaction addToBackStack

List of usage examples for android.app FragmentTransaction addToBackStack

Introduction

In this page you can find the example usage for android.app FragmentTransaction addToBackStack.

Prototype

public abstract FragmentTransaction addToBackStack(@Nullable String name);

Source Link

Document

Add this transaction to the back stack.

Usage

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 v  a  2  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:rtdc.android.presenter.InCallActivity.java

public void displayVideo() {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    callFragment = new VideoCallFragment();
    transaction.replace(R.id.in_call_fragment_wrapper, callFragment);
    transaction.addToBackStack(null);
    transaction.commit();/*from w  w w. j a  v  a  2s  .  co m*/
}

From source file:rtdc.android.presenter.InCallActivity.java

public void displayAudio() {
    if (AndroidVoipController.get().isVideoEnabled())
        AndroidVoipController.get().setVideo(false);
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    callFragment = new AudioCallFragment();
    transaction.replace(R.id.in_call_fragment_wrapper, callFragment);
    transaction.addToBackStack(null);
    transaction.commit();//from  w  ww .  j a v  a2s .c o m
}

From source file:com.aokp.romcontrol.github.tasks.DisplayProjectsListTask.java

private void addPropertiesToPreference(PreferenceCategory mProject, JSONObject projectsObject) {
    try {//from   w w w .j  av a 2 s  .c  om
        // extract info about each project
        final String projectName = projectsObject.getString("name");
        String projectDescription = projectsObject.getString("description");
        int githubProjectId = projectsObject.getInt("id");
        // apply info to our preference screen
        mProject.setKey(projectName);
        if (projectDescription.contains("") || projectDescription == null) {
            mProject.setTitle(projectName);
            mProject.setSummary(projectDescription);
        } else {
            mProject.setTitle(projectDescription);
            mProject.setSummary(projectName);
        }
        mProject.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference p) {
                FragmentTransaction transaction = mFragmentManager.beginTransaction();
                CommitsFragment commitFragment = new CommitsFragment(mAlertDialog, projectName);
                transaction.addToBackStack(null);
                transaction.replace(mId, commitFragment, projectName);
                transaction.commit();
                return true;
            }
        });
    } catch (JSONException badJsonRequest) {
        Log.e(TAG, "failed to parse required info about project", badJsonRequest);
    }
}

From source file:com.kevinshen.beyondupnp.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_select) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        Fragment prev = getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG);
        if (prev != null) {
            ft.remove(prev);//from   w  w  w .ja va 2  s.com
        }
        ft.addToBackStack(null);

        // Create and show the dialog.
        DialogFragment newFragment = DeviceListDialogFragment.newInstance();
        newFragment.show(ft, DIALOG_FRAGMENT_TAG);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.android.tv.settings.dialog.DialogFragment.java

public static void add(FragmentManager fm, DialogFragment f) {
    boolean hasDialog = fm.findFragmentByTag(TAG_LEAN_BACK_DIALOG_FRAGMENT) != null;
    FragmentTransaction ft = fm.beginTransaction();

    if (hasDialog) {
        ft.setCustomAnimations(ANIMATION_FRAGMENT_ENTER, ANIMATION_FRAGMENT_EXIT, ANIMATION_FRAGMENT_ENTER_POP,
                ANIMATION_FRAGMENT_EXIT_POP);
        ft.addToBackStack(null);
    }//from  w  w  w. ja va  2 s.c  om
    ft.replace(android.R.id.content, f, TAG_LEAN_BACK_DIALOG_FRAGMENT).commit();
}

From source file:com.sage42.androidappaddicts.app.main.MainActivity.java

public void showFragment(final Fragment fragment, final boolean addToBackstack) {
    final FragmentManager fragmentManager = this.getFragmentManager();
    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.main_content_fragment, fragment);
    if (addToBackstack) {
        transaction.addToBackStack(null);

    } else {//from   w ww  .  java 2  s .  c om
        this.clearAllBackStack();

        this.mDrawerToggle.syncState();
    }
    transaction.commit();

    // close the drawer
    this.mDrawerLayout.closeDrawer(this.mMenuDrawerList);
}

From source file:com.example.ogadrive.HomeActivity2.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;/*from ww  w.  j a v  a 2s .c  o m*/

    if (position == 1) {
        /*fragment = new HomeFragement();
        fragment.setArguments(bundle);*/

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    } else if (position == 0) {
        fragment = new FragmentProfile();
        fragment.setArguments(bundle);

    } else if (position == 2) {

        setTitle("Contact Us");
    } else if (position == 3) {

        fragment = new FragmentHistory();
        fragment.setArguments(bundle);
    }

    if (fragment == null) {
        fragment = new HomeFragement();
        fragment.setArguments(bundle);
    }

    FragmentManager fragmentManager = getFragmentManager();
    // fragmentManager.popBackStack();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    fragmentTransaction.add(R.id.content_frame, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
    // fragmentTransaction.addToBackStack("hradesh").commit();
    // fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount()-1);

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);

    // }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.galois.qrstream.MainActivity.java

private void showFragment(Fragment fragment, boolean addToBackStack) {
    FragmentTransaction ft = fragmentManager.beginTransaction();

    // Replace null parameter with string only if
    // change to ft.replace(int,Fragment,String)
    ft.replace(R.id.container, fragment);
    if (addToBackStack) {
        ft.addToBackStack(null);
    }//from w w w. j  av a2s  .c  om
    ft.commit();
    lastFragment = currentFragment;
    currentFragment = fragment;
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

/**
 * Adds the specified GuidedStepFragment to the fragment stack, replacing any existing
 * GuidedStepFragments in the stack, and configuring the fragment-to-fragment custom
 * transitions.  A backstack entry is added, so the fragment will be dismissed when BACK key
 * is pressed.//  w w  w .  j  a v  a  2 s. c o  m
 * <li>If current fragment on stack is GuidedStepFragment: assign {@link #UI_STYLE_REPLACE} and
 * {@link #onAddSharedElementTransition(FragmentTransaction, GuidedStepFragment)} will be called
 * to perform shared element transition between GuidedStepFragments.
 * <li>If current fragment on stack is not GuidedStepFragment: assign {@link #UI_STYLE_ENTRANCE}
 * <p>
 * Note: currently fragments added using this method must be created programmatically rather
 * than via XML.
 * @param fragmentManager The FragmentManager to be used in the transaction.
 * @param fragment The GuidedStepFragment to be inserted into the fragment stack.
 * @param id The id of container to add GuidedStepFragment, can be android.R.id.content.
 * @return The ID returned by the call FragmentTransaction.commit.
 */
public static int add(FragmentManager fragmentManager, GuidedStepFragment fragment, int id) {
    GuidedStepFragment current = getCurrentGuidedStepFragment(fragmentManager);
    boolean inGuidedStep = current != null;
    if (IS_FRAMEWORK_FRAGMENT && Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23 && !inGuidedStep) {
        // workaround b/22631964 for framework fragment
        fragmentManager.beginTransaction().replace(id, new DummyFragment(), TAG_LEAN_BACK_ACTIONS_FRAGMENT)
                .commit();
    }
    FragmentTransaction ft = fragmentManager.beginTransaction();

    fragment.setUiStyle(inGuidedStep ? UI_STYLE_REPLACE : UI_STYLE_ENTRANCE);
    ft.addToBackStack(fragment.generateStackEntryName());
    if (current != null) {
        fragment.onAddSharedElementTransition(ft, current);
    }
    return ft.replace(id, fragment, TAG_LEAN_BACK_ACTIONS_FRAGMENT).commit();
}