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:dtu.ds.warnme.app.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_login) {
        Log.d(TAG, "Showing login dialog...");

        FragmentTransaction ft = getFragmentManager().beginTransaction();
        Fragment prev = getFragmentManager().findFragmentByTag(LoginDialog.class.getName());
        if (prev != null) {
            ft.remove(prev);//from   w  w w.j  a  v a2  s .  co m
        }
        ft.addToBackStack(null);

        LoginDialog ld = new LoginDialog();
        ld.show(ft, LoginDialog.class.getName());
        return true;
    }
    if (id == R.id.action_register) {
        Log.d(TAG, "Showing register dialog...");

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

        RegisterDialog rd = new RegisterDialog();
        rd.show(ft, RegisterDialog.class.getName());
        return true;
    }
    if (id == R.id.action_logout) {
        Log.d(TAG, "Logging out...");

        UserProfileHolder.clear();
        Prefs.setUsername(StringUtils.EMPTY);
        Prefs.setPasswordHash(StringUtils.EMPTY);

        updateUserInterface();
        return true;
    }
    if (id == R.id.action_settings) {
        Log.d(TAG, "Moving to Settings activity...");

        Intent settingsActivityIntent = new Intent(this, SettingsActivity.class);
        startActivity(settingsActivityIntent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.battlelancer.seriesguide.ui.SeriesGuidePreferences.java

public void switchToSettings(String settingsId) {
    Bundle args = new Bundle();
    args.putString("settings", settingsId);
    Fragment f = new SettingsFragment();
    f.setArguments(args);/*from w w w  .j  a  va 2  s .  co  m*/
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.content_frame, f);
    ft.addToBackStack(null);
    ft.commit();
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    map.setMyLocationEnabled(true);// w w  w.j a  v a2 s . com
    map.getUiSettings().setAllGesturesEnabled(true);
    map.getUiSettings().setCompassEnabled(true);

    locationSource = new FollowMeLocationSource(this, getApplicationContext(), map);
    locationSource.getBestAvailableProvider();
    map.setLocationSource(locationSource);

    buttonReport = (Button) findViewById(R.id.button_report);
    buttonReport.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            buttonReport.setEnabled(false);

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

            Bundle args = new Bundle();
            args.putParcelable(KEY_CURRENT_LOCATION, locationSource.getCurrentLocation());

            ReportDialog reportDialog = new ReportDialog();
            reportDialog.setArguments(args);
            reportDialog.show(ft, ReportDialog.class.getName());
        }
    });

    verifyLogin();
}

From source file:com.rubixconsulting.walletcracker.WalletCrackerMain.java

private void showError(Integer messageId) {
    if ((messageId == null) || (messageId == 0)) {
        Log.i(TAG, "Not showing invalid error");
        return;//from  w w w.j a  va  2  s .  c om
    }

    Log.e(TAG, "Error: " + getString(messageId));

    FragmentTransaction ft = getFragmentManager().beginTransaction();

    // remove any previous error fragments
    Fragment prev = getFragmentManager().findFragmentByTag(ErrorDialogFragment.TAG);
    if (prev != null) {
        ft.remove(prev);
    }

    // add the new error
    ft.addToBackStack(null);
    ErrorDialogFragment fragment = ErrorDialogFragment.newInstance(messageId);
    fragment.show(ft, ErrorDialogFragment.TAG);

    // see note about this in showProgress
    getFragmentManager().executePendingTransactions();
}

From source file:produvia.com.scanner.DevicesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mErrorOccurred = false;/*  w w w . j a  v a2s .c  o  m*/
    mErrorMessage = "";
    setContentView(R.layout.activity_devices);

    listFragment = new DevicesFragment();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.main_fragment, listFragment);
    transaction.addToBackStack(null);

    // Commit the transaction
    transaction.commit();
    //Start running the discovery service in the background
    //any discovered services will be reported on the onTaskUpdate callback:
    boolean run_discovery = true;
    Calendar time_now = Calendar.getInstance();
    if (mScanCycleCounter > 0 && mLastScanStartedAt != null) {

        if (time_now.getTimeInMillis()
                - mLastScanStartedAt.getTimeInMillis() < MINIMUM_TIME_BETWEEN_SCANS_MILLIS)
            run_discovery = false;
    }
    if (run_discovery) {

        mLastScanStartedAt = time_now;
        showScanProgress(true);
        WeaverSdkApi.discoveryService(this, true);
    }
    //fetch the services that have already been discovered in previous scans
    //these services will be returned in the onTaskCompleted callback:
    WeaverSdkApi.servicesGet(this, null);
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void showFragment(final FragmentManager fragmentManager, final Fragment fragment,
        final boolean addToBackStack, final String tag) {
    // hide the full screen container
    hideFullScreenView();/*  w  w w. j  a v a2 s  . c om*/

    if (fragmentManager.findFragmentByTag(tag) == null) {
        final int viewId = mContentContainer.addBorderView(this);
        updateCurrentPresenterClass(fragment, viewId);

        final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(viewId, fragment, tag);
        if (addToBackStack) {
            transaction.addToBackStack(tag);
        }
        transaction.commitAllowingStateLoss();
    } else {
        fragmentManager.beginTransaction().detach(fragment).attach(fragment).commitAllowingStateLoss();
    }
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void showMirrorView(final FragmentManager fragmentManager, final MirrorView mirrorView,
        final boolean addToBackStack, final String tag) {
    if (mirrorView.isFullscreen()) {
        mFullscreenContainer.setVisibility(View.VISIBLE);

        final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(getContainerViewId(), (Fragment) mirrorView, tag);
        if (addToBackStack) {
            transaction.addToBackStack(tag);
        }//from ww w.j av a2 s .  c  o m
        transaction.commitAllowingStateLoss();
    } else {
        showFragment(fragmentManager, (Fragment) mirrorView, addToBackStack, tag);
    }
}

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

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {/*from  w  w  w .  j a va 2  s. 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:me.pzheng.conn.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fm = getFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();

    // debug code
    // Toast.makeText(this, "Menu item selected -> " + position, Toast.LENGTH_SHORT).show();

    Fragment fragment;//from   w w  w .j  a v  a2 s.  com
    switch (position) {
    case 0: //connect
        fragment = fm.findFragmentByTag(ConnectFragment.TAG);
        if (fragment == null) {
            fragment = new ConnectFragment();
        }
        transaction.replace(R.id.container, fragment, ConnectFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();
        break;
    case 1: //settings
        /* fragment = getFragmentManager().findFragmentByTag(StatsFragment.TAG);
        if (fragment == null) {
            fragment = new StatsFragment();
        }
        getFragmentManager().beginTransaction().replace(R.id.container, fragment, StatsFragment.TAG).commit(); */
        fragment = fm.findFragmentByTag(SettingsFragment.TAG);
        if (fragment == null) {
            fragment = new SettingsFragment();
        }
        transaction.replace(R.id.container, fragment, SettingsFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();
        break;
    case 2: //about
        fragment = fm.findFragmentByTag(AboutFragment.TAG);
        if (fragment == null) {
            fragment = new AboutFragment();
        }
        transaction.replace(R.id.container, fragment, AboutFragment.TAG);
        transaction.addToBackStack(null);
        transaction.commit();
        break;
    }

    //transaction.commit();

}

From source file:com.silentcircle.silenttext.activity.AccountCreationActivity.java

@Override
public void onNext(Fragment fragment) {
    FragmentTransaction tx = getFragmentManager().beginTransaction();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        tx.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);
    }/*from   w ww. j  a v a 2 s  .  co  m*/

    if (tx.isAddToBackStackAllowed()) {
        tx.addToBackStack(null);
    }
    tx.replace(R.id.content, fragment);
    tx.commit();
}