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.android.mail.browse.AttachmentActionHandler.java

/**
 * Displays a loading dialog to be used for downloading attachments.
 * Must be called on the UI thread./*  ww  w  .  ja v a  2s  .c  om*/
 */
public void showDownloadingDialog() {
    final FragmentTransaction ft = mFragmentManager.beginTransaction();
    final Fragment prev = mFragmentManager.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    final DialogFragment newFragment = AttachmentProgressDialogFragment.newInstance(mAttachment);
    newFragment.show(ft, PROGRESS_FRAGMENT_TAG);
}

From source file:de.sourcestream.movieDB.controller.GalleryList.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *///from w w  w .  j  ava2  s  .co m
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle args = new Bundle();
    args.putStringArrayList("galleryList", galleryPath);
    args.putInt("currPos", position);
    galleryPreview.setArguments(args);
    transaction.replace(R.id.frame_container, galleryPreview);
    // add the current transaction to the back stack:
    transaction.addToBackStack("galleryList");
    transaction.commit();

}

From source file:com.optimusinfo.elasticpath.cortex.common.EPFragmentActivity.java

/**
 * This method adds a fragment to the current activity
 * //from www  .j a  va2s.  com
 * @param title
 * @param isNew
 * @param tag
 * @param fargmentContainerId
 * @param objFragment
 */
public void addFragmentToBreadCrumb(String title, int fargmentContainerId, EPFragment objFragment) {
    String breadTitle = title;
    if (title.length() > 16) {
        breadTitle = title.substring(0, 14).concat(getString(R.string.ellipsis));
    }
    mStackLevel++;
    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setBreadCrumbTitle(breadTitle);
    ft.replace(fargmentContainerId, objFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();

}

From source file:edu.jcu.cs470.togenda.MainActivity.java

private void selectItem(int position) {
    //switches to the correct fragment.

    Fragment newFragment;/*from ww w.  ja  va2 s  .c  om*/
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    switch (position) {
    case 0:
        newFragment = new AgendaFragment();
        transaction.replace(R.id.content_frame, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();
        gPosition = position;
        setTitle(pageList[position]);
        break;
    case 1:
        Log.d("Case1", "test");
        newFragment = new ToDoFragment();
        transaction.replace(R.id.content_frame, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();
        Log.d("Case1", "test");
        gPosition = position;
        setTitle(pageList[position]);
        break;
    case 2:
        newFragment = new CalendarFragment();
        transaction.replace(R.id.content_frame, newFragment);
        transaction.addToBackStack(null);
        transaction.commit();
        gPosition = position;
        setTitle(pageList[position]);
        break;
    case 3:
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        break;
    }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.ternup.caddisfly.activity.MainActivity.java

/**
 * Display view fragment for selected nav drawer menu option
 *///from w w w  . j a  v a  2  s .  co m
public void displayView(int position, boolean addToBackStack) {

    int index = getCurrentFragmentIndex();

    if (index == position) {
        // requested fragment is already showing
        return;
    }

    Fragment fragment;
    showCheckUpdateOption = false;
    switch (position) {
    case Globals.HOME_SCREEN_INDEX:
        if (homeFragment == null) {
            homeFragment = new HomeFragment();
        }
        fragment = homeFragment;
        break;
    case Globals.LOCATION_LIST_SCREEN_INDEX:
        if (mLocationListFragment == null) {
            mLocationListFragment = new LocationListFragment();
        }
        fragment = mLocationListFragment;
        break;
    case Globals.CALIBRATE_SCREEN_INDEX:
        if (calibrateFragment == null) {
            calibrateFragment = new CalibrateFragment();
        }
        fragment = calibrateFragment;
        break;
    case Globals.SETTINGS_SCREEN_INDEX:
        showCheckUpdateOption = true;
        if (settingsFragment == null) {
            settingsFragment = new SettingsFragment();
        }
        fragment = settingsFragment;
        break;
    case Globals.HELP_SCREEN_INDEX:
        showCheckUpdateOption = true;
        if (helpFragment == null) {
            helpFragment = new HelpFragment();
        }
        fragment = helpFragment;
        break;
    case Globals.ABOUT_SCREEN_INDEX:
        showCheckUpdateOption = true;
        if (aboutFragment == null) {
            aboutFragment = new AboutItFragment();
        }
        fragment = aboutFragment;
        break;
    default:
        toggleTheme();
        return;
    }
    invalidateOptionsMenu();
    if (fragment != null) {

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.replace(R.id.container, fragment, String.valueOf(position));
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        if (addToBackStack) {
            ft.addToBackStack(null);
        }
        ft.commit();
    }
    mNavigationDrawerFragment.checkItem(position);
}

From source file:org.physical_web.physicalweb.MainActivity.java

@SuppressLint("CommitTransaction")
private void showFragment(Fragment newFragment, String fragmentTag, boolean addToBackStack) {
    FragmentTransaction transaction = getFragmentManager().beginTransaction()
            .setCustomAnimations(R.animator.fade_in_and_slide_up_fragment, R.animator.fade_out_fragment,
                    R.animator.fade_in_activity, R.animator.fade_out_fragment)
            .replace(R.id.main_activity_container, newFragment, fragmentTag);
    if (addToBackStack) {
        transaction.addToBackStack(null);
    }//  w  w  w. j  ava2s . c  om
    transaction.commit();
}

From source file:me.isassist.isa.MainActivity.java

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

    Fragment fragment = new ListFragment();
    Bundle args = new Bundle();

    if (mLastLocation == null) {
        Toast.makeText(this, "Waiting for the location...", Toast.LENGTH_LONG).show();
        return false;
    }

    switch (id) {
    case R.id.nav_atms: {
        args.putSerializable("API_TYPE", Bihapi.CASH_MACHINES);
        mListType = Bihapi.CASH_MACHINES;
        break;
    }
    case R.id.nav_bikes: {
        args.putSerializable("API_TYPE", Bihapi.VETURILO);
        mListType = Bihapi.VETURILO;
        break;
    }
    case R.id.nav_city_offices: {
        args.putSerializable("API_TYPE", Bihapi.CITY_OFFICES);
        mListType = Bihapi.CITY_OFFICES;
        break;
    }
    case R.id.nav_dormitories: {
        args.putSerializable("API_TYPE", Bihapi.DORMITORIES);
        mListType = Bihapi.DORMITORIES;
        break;
    }
    case R.id.nav_hotels: {
        args.putSerializable("API_TYPE", Bihapi.HOTELS);
        mListType = Bihapi.HOTELS;
        break;
    }
    case R.id.nav_pharmacies: {
        args.putSerializable("API_TYPE", Bihapi.PHARMACIES);
        mListType = Bihapi.PHARMACIES;
        break;
    }
    case R.id.nav_sport_fields: {
        args.putSerializable("API_TYPE", Bihapi.SPORT_FIELDS);
        mListType = Bihapi.SPORT_FIELDS;
        break;
    }
    case R.id.nav_swimming: {
        args.putSerializable("API_TYPE", Bihapi.SWIMMING_POOLS);
        mListType = Bihapi.SWIMMING_POOLS;
        break;
    }
    case R.id.nav_police_offices: {
        args.putSerializable("API_TYPE", Bihapi.POLICE_OFFICES);
        mListType = Bihapi.POLICE_OFFICES;
        break;
    }
    case R.id.nav_theaters: {
        args.putSerializable("API_TYPE", Bihapi.THEATRES);
        mListType = Bihapi.THEATRES;
        break;
    }
    }
    fragment.setArguments(args);

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();

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

From source file:com.esri.android.mapsapp.MapsAppActivity.java

/**
 * Opens the content browser that shows the user's maps.
 *//*  w  w w .  jav a  2  s. c o  m*/
private void showContentBrowser() {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment browseFragment = fragmentManager.findFragmentByTag(ContentBrowserFragment.TAG);
    if (browseFragment == null) {
        browseFragment = new ContentBrowserFragment();
    }

    if (!browseFragment.isVisible()) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.maps_app_activity_content_frame, browseFragment, ContentBrowserFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();

        invalidateOptionsMenu(); // reload the options menu
    }

    mDrawerLayout.closeDrawers();
}

From source file:dtu.ds.warnme.app.activity.MainActivity.java

@Override
public void onApproachingEvent(Event event) {
    if (warningDialog != null && event.equals(warningDialog.getEvent())) {
        return;//from  w ww . j a v a2 s. c o  m
    }

    if (alreadyWarned.contains(event)) {
        return;
    }
    alreadyWarned.add(event);

    if (warningDialog != null) {
        warningDialog.dismiss();
    }

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag(LoginDialog.class.getName());
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    Bundle args = new Bundle();
    args.putSerializable(KEY_EVENT, event);

    warningDialog = new WarningDialog();
    warningDialog.setEvent(event);
    warningDialog.setArguments(args);
    warningDialog.show(ft, WarningDialog.class.getName());
}

From source file:com.QuarkLabs.BTCeClient.MainActivity.java

/**
 * Displays selected fragment/*  w ww  .  j  a v  a 2  s . c  o  m*/
 *
 * @param position Position at the list (0-based)
 */
private void displayItem(final int position) {
    Fragment fragment = null;
    final FragmentManager fragmentManager = getFragmentManager();
    switch (position) {
    case 0:
        fragment = mHomeFragment;
        fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        break;
    case 1:
        fragment = new OrdersBookFragment();
        break;
    case 2:
        fragment = new ActiveOrdersFragment();
        break;
    case 3:
        fragment = HistoryFragment.newInstance(ListType.Trades);
        break;
    case 4:
        fragment = HistoryFragment.newInstance(ListType.Transactions);
        break;
    case 5:
        fragment = new ChartsFragment();
        break;
    case 6:
        fragment = new SettingsFragment();
        break;
    case 7:
        fragment = new NotifiersFragment();
        break;
    case 8:
        fragment = new HelpFragment();
        break;
    default:
        break;
    }
    final Fragment fr = fragment;
    if (fr != null) {
        //delay in msecs
        int delay = 250;
        //post delayed for smooth behaviour
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                FragmentTransaction transaction = fragmentManager.beginTransaction()
                        .setCustomAnimations(R.animator.fade_in, R.animator.fade_out)
                        .replace(R.id.content_frame, fr);
                if (position != 0) {
                    transaction.addToBackStack(String.valueOf(position)); //name of fragment = position
                }
                transaction.commit();
                setTitle(mDrawerListItems[position]);
            }
        }, delay);
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        if (mDrawerLayout != null) {
            mDrawerLayout.closeDrawer(mDrawerList);
        }
    }
}