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:it.mobistego.MainActivity.java

@Override
public void itemViewOnDelete(MobiStegoItem mobiStegoItem) {

    DeleteDialogFragment deleteDialogFragment = new DeleteDialogFragment();
    Bundle args = new Bundle();
    deleteDialogFragment.setMobiStegoItem(mobiStegoItem);
    deleteDialogFragment.setArguments(args);
    FragmentTransaction transaction = getFragmentManager().beginTransaction();

    transaction.addToBackStack(null);
    deleteDialogFragment.show(transaction, "dialogdelete");

}

From source file:it.mobistego.MainActivity.java

@Override
public void onMainFragmentBitmapSelectedToEncode(File btm) {
    if (btm != null) {
        ComposeFragment compose = new ComposeFragment();
        Bundle args = new Bundle();
        compose.setChoosenBitmap(btm);// w ww . ja va2 s  . c om
        compose.setArguments(args);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        transaction.addToBackStack(null);
        compose.show(transaction, "dialog");

    }
}

From source file:com.example.kyle.fragmentexample.MainActivity.java

public void replaceFragment(Fragment fragment) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    transaction.replace(R.id.fragment_container, fragment);
    transaction.addToBackStack(null);
    transaction.commit();//from   w w w. j  a v a 2 s . c o m
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_browser.search.video.SignSearchVideoActivity.java

private void showSignVideoFragment(SignVideoFragment signVideoFragment) {
    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.searchVideoActivityContentFrame, signVideoFragment, "SIGN_VIDEO_TAG");
    transaction.addToBackStack(null);
    transaction.commit();//from w w w.  ja va 2 s .c  o m
}

From source file:fr.qinder.layout.DrawerLayoutActivity.java

public void setContentFragment(String className, boolean withHistory) {
    DrawerLayoutFragment fragment;//from ww  w .  j a  v a2 s .  c  om
    try {
        fragment = (DrawerLayoutFragment) Class.forName(className).newInstance();
    } catch (InstantiationException e) {
        fragment = null;
    } catch (IllegalAccessException e) {
        fragment = null;
    } catch (ClassNotFoundException e) {
        fragment = null;
    }
    if (fragment != null) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(mDrawerLayoutContent, fragment);
        if (withHistory) {
            ft.addToBackStack(null);
        }
        ft.commit();
        getSupportActionBar().setTitle(fragment.getTitle());
    }
}

From source file:org.code4hr.okcandidate.HomeActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from ww  w.  j  ava2 s  .  c o m*/
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    switch (id) {
    case R.id.nav_survey: {

        FragmentTransaction tx = getFragmentManager().beginTransaction();
        tx.replace(R.id.content_frame, new NeighborhoodsFragment());
        tx.addToBackStack(null);
        tx.commit();
        break;
    }
    case R.id.nav_results: {
        SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
        int survey_id = sharedPreferences.getInt("survey_response_id", 0);
        if (survey_id != 0) {
            FragmentTransaction tx = getFragmentManager().beginTransaction();
            tx.replace(R.id.content_frame, CandidateFragment.newInstance(survey_id));
            tx.addToBackStack(null);
            tx.commit();
        } else {
            Toast.makeText(this, R.string.no_survey_error, Toast.LENGTH_SHORT).show();
        }
        break;
    }
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java

/**
 * Adds the specified GuidedStepListFragment to the fragment stack, replacing any existing
 * GuidedStepListFragments 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 ww  . j  a  va 2 s .  c o  m
 * <li>If current fragment on stack is GuidedStepListFragment: assign {@link #UI_STYLE_REPLACE} and
 * {@link #onAddSharedElementTransition(FragmentTransaction, GuidedStepListFragment)} will be called
 * to perform shared element transition between GuidedStepListFragments.
 * <li>If current fragment on stack is not GuidedStepListFragment: 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 GuidedStepListFragment to be inserted into the fragment stack.
 * @param id              The id of container to add GuidedStepListFragment, can be android.R.id.content.
 * @return The ID returned by the call FragmentTransaction.commit.
 */
public static int add(FragmentManager fragmentManager, GuidedStepListFragment fragment, int id) {
    GuidedStepListFragment current = getCurrentGuidedStepListFragment(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();
}

From source file:com.TurnOrder.MainActivity.java

private void changeNavItem(int position, Player p) {
    Fragment fragment = null;/*from w  w  w  .  ja  va 2  s  . co m*/
    switch (position + 1) {
    case 1:
        fragment = new FragmentHome();
        setTitleMenu(titlemenue, "Home");

        break;
    case 2:
        fragment = new FragmentAddPlayer();
        setTitleMenu(titlemenue, "Add Player");
        break;
    case 3:
        fragment = new FragmentViewPlayer(p, playerList);
        setTitleMenu(titlemenue, "View Player");
        break;
    case 4:
        fragment = new FragmentPlay(playerList);
        setTitleMenu(titlemenue, "Play");
        break;
    case 5:
        fragment = new FragmentSplash();
        setTitleMenu(titlemenue, "Savage Worlds Licence");
    }

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    fragmentTransaction.replace(R.id.container, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.example.android.reward.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new EndTripFragment();
    Bundle args = new Bundle();
    args.putInt(EndTripFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);/*from   w ww  .  j  a v  a  2 s . co m*/

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    //ft.replace(R.id.content_frame, fragment);
    ft.add(R.id.content_frame, fragment);

    ft.addToBackStack("null");
    ft.commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java

private void setFragment(Fragment fragment, String actionBarTitle) {
    Log.d(TAG, "setFragment: " + actionBarTitle + StringUtils.SPACE + hashCode());
    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.content_frame, fragment, actionBarTitle);
    transaction.addToBackStack(actionBarTitle);
    transaction.commit();/*from w  ww  .ja va  2  s.co m*/
}