Example usage for android.support.v4.app FragmentTransaction commitAllowingStateLoss

List of usage examples for android.support.v4.app FragmentTransaction commitAllowingStateLoss

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction commitAllowingStateLoss.

Prototype

public abstract int commitAllowingStateLoss();

Source Link

Document

Like #commit but allows the commit to be executed after an activity's state is saved.

Usage

From source file:com.sim2dial.dialer.LinphoneActivity.java

private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType,
        boolean withoutAnimation) {
    if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
        if (newFragmentType == FragmentsAvailable.DIALER) {
            showStatusBar();/* w ww .j a  v  a2 s  . c om*/
            // hideStatusBar();
        } else {
            hideStatusBar();
        }
    }

    // if (statusFragment != null)
    // {
    // statusFragment.closeStatusBar();
    // }

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
        if (newFragmentType.isRightOf(currentFragment)) {
            transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left,
                    R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
        } else {
            transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right,
                    R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
        }
    }
    try {
        getSupportFragmentManager().popBackStackImmediate(newFragmentType.toString(),
                FragmentManager.POP_BACK_STACK_INCLUSIVE);
    } catch (java.lang.IllegalStateException e) {

    }

    transaction.addToBackStack(newFragmentType.toString());
    transaction.replace(R.id.fragmentContainer, newFragment);
    transaction.commitAllowingStateLoss();
    getSupportFragmentManager().executePendingTransactions();

    currentFragment = newFragmentType;
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java

public void showDialog(FragmentManager fm, Fragment frag, final String op_type, final String c_grp,
        final ProfileListItem tpli) {
    if (DEBUG_ENABLE)
        Log.v(APPLICATION_TAG, "showDialog");
    mTerminateRequired = false;/*  w w w. j a  v  a2 s.  co  m*/
    mOpType = op_type;
    mCurrentGroup = c_grp;
    mCurrentProfileListItem = tpli;
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(frag, null);
    ft.commitAllowingStateLoss();
    //       show(fm,APPLICATION_TAG);
}

From source file:com.tencent.wstt.gt.activity.GTParamTopFragment.java

/**
 * ?index??Fragment/*from   www .  j ava 2s. c o  m*/
 * 
 * @param index
 *            ?Fragment
 */
private void setFragSelection(int index) {
    // ???
    clearSelection();
    // ?Fragment
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    // ??FragmentFragment?
    hideFragments(transaction);

    switch (index) {
    case 0:
        // ?
        btnIn.setBackgroundResource(R.drawable.swbtn_selected);
        btnIn.setTextColor(Color.WHITE);
        if (inFragment == null) {
            inFragment = new GTParamInFragment();
            transaction.add(R.id.content, inFragment);
        } else {
            transaction.show(inFragment);
        }
        break;
    case 1:
        // ?
        btnOut.setBackgroundResource(R.drawable.swbtn_selected);
        btnOut.setTextColor(Color.WHITE);
        if (outFragment == null) {
            outFragment = new GTParamOutFragment();
            transaction.add(R.id.content, outFragment);
        } else {
            transaction.show(outFragment);
        }
        break;
    case 2:
        // ?
        btnIn.setBackgroundResource(R.drawable.swbtn_selected);
        btnIn.setTextColor(Color.WHITE);
        if (inEditFragment == null) {
            inEditFragment = new GTParamInEditFragment();
            transaction.add(R.id.content, inEditFragment);
        } else {
            transaction.show(inEditFragment);
        }
        break;
    case 3:
        // ?
        btnOut.setBackgroundResource(R.drawable.swbtn_selected);
        btnOut.setTextColor(Color.WHITE);
        if (outEditFragment == null) {
            outEditFragment = new GTParamOutEditFragment();
            transaction.add(R.id.content, outEditFragment);
        } else {
            transaction.show(outEditFragment);
        }
        break;
    default:
        break;
    }
    /*
     * commit()?
     * IllegalStateException: Can not perform this action after onSaveInstanceState\
     * 
     * @see http://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss()
     * 
     * ?? commitActivityonSaveInstanceState()?onSaveInstanceState
     * Activity?????Activity?????Fragment
     * commit?? commitAllowingStateLoss()
     */
    // transaction.commit(); 
    transaction.commitAllowingStateLoss();
}

From source file:org.linphone.LinphoneActivity.java

private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType,
        boolean withoutAnimation) {
    //      if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
    //         if (newFragmentType == FragmentsAvailable.DIALER) {
    //            showStatusBar();
    //         } else {
    //            hideStatusBar();
    //         }/* www  .j av a2  s .  co  m*/
    //      }
    if (statusFragment != null) {
        statusFragment.closeStatusBar();
    }

    LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) {
        ll.setVisibility(View.VISIBLE);

        transaction.addToBackStack(newFragmentType.toString());
        transaction.replace(R.id.fragmentContainer2, newFragment);
    } else {
        if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.ABOUT
                || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
                || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS
                || newFragmentType == FragmentsAvailable.SETTINGS
                || newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) {
            ll.setVisibility(View.GONE);
        } else {
            ll.setVisibility(View.INVISIBLE);
        }

        if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
            if (newFragmentType.isRightOf(currentFragment)) {
                transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left,
                        R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
            } else {
                transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right,
                        R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
            }
        }
        transaction.replace(R.id.fragmentContainer, newFragment);
    }
    transaction.commitAllowingStateLoss();
    getSupportFragmentManager().executePendingTransactions();

    currentFragment = newFragmentType;
    if (newFragmentType == FragmentsAvailable.DIALER
            || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
            || newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS
            || newFragmentType == FragmentsAvailable.SETTINGS || newFragmentType == FragmentsAvailable.CONTACTS
            || newFragmentType == FragmentsAvailable.CHATLIST
            || newFragmentType == FragmentsAvailable.HISTORY) {
        try {
            getSupportFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        } catch (IllegalStateException e) {

        }
    }
    fragmentsHistory.add(currentFragment);
}

From source file:com.igniva.filemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;/* ww  w  . ja  v a  2 s  .c  om*/
    path = i.getStringExtra("path");
    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                Main m = ((Main) getFragment().getTab());
                m.loadlist(path, false, 0);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra("failedOps") != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra("failedOps");
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if ((openprocesses = i.getBooleanExtra("openprocesses", false))) {

        android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer());
        //   transaction.addToBackStack(null);
        select = 102;
        openprocesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null)
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {

            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }
}

From source file:com.amaze.filemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;/*from w  w  w.jav a  2 s . c  om*/
    path = i.getStringExtra("path");
    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                Main m = ((Main) getFragment().getTab());
                m.loadlist(path, false, 0);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra("failedOps") != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra("failedOps");
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if ((openprocesses = i.getBooleanExtra("openprocesses", false))) {

        android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer());
        //   transaction.addToBackStack(null);
        select = 102;
        openprocesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null)
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {

            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {

            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }
}

From source file:org.xingjitong.LinphoneActivity.java

private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType,
        boolean withoutAnimation) {
    if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
        if (newFragmentType == FragmentsAvailable.DIALER) {
            showStatusBar();/*  w  ww  .ja v  a  2 s.c o  m*/
        } else {
            hideStatusBar();
        }
    }

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
        if (newFragmentType.isRightOf(currentFragment)) {
            transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left,
                    R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
        } else {
            transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right,
                    R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
        }
    }
    //      try {
    //         getSupportFragmentManager().popBackStackImmediate(
    //               newFragmentType.toString(),
    //               FragmentManager.POP_BACK_STACK_INCLUSIVE);
    //      } catch (java.lang.IllegalStateException e) {//?? 
    //
    //      }

    transaction.addToBackStack(newFragmentType.toString());
    transaction.replace(R.id.fragmentContainer, newFragment);
    if (isInstanciated()) {
        try {
            transaction.commitAllowingStateLoss();
        } catch (Exception e) {
        }
    }
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            getSupportFragmentManager().executePendingTransactions();
        }
    });

    currentFragment = newFragmentType;
}

From source file:com.amaze.filemanager.activities.MainActivity.java

public void goToMain(String path) {
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    //title.setText(R.string.app_name);
    TabFragment tabFragment = new TabFragment();
    if (path != null && path.length() > 0) {
        Bundle b = new Bundle();
        b.putString("path", path);
        tabFragment.setArguments(b);/*from  ww  w  .j  a  v  a 2 s.  c o m*/
    }
    transaction.replace(R.id.content_frame, tabFragment);
    // Commit the transaction
    select = 0;
    transaction.addToBackStack("tabt" + 1);
    transaction.commitAllowingStateLoss();
    setActionBarTitle(null);
    floatingActionButton.setVisibility(View.VISIBLE);
    floatingActionButton.showMenuButton(true);
    if (openzip && zippath != null) {
        if (zippath.endsWith(".zip") || zippath.endsWith(".apk"))
            openZip(zippath);
        else {
            openRar(zippath);
        }
        zippath = null;
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

public void openZip(String path) {
    findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.slide_in_top, R.anim.slide_in_bottom);
    Fragment zipFragment = new ZipViewer();
    Bundle bundle = new Bundle();
    bundle.putString("path", path);
    zipFragment.setArguments(bundle);//from  w  w  w. java  2 s . c om
    fragmentTransaction.add(R.id.content_frame, zipFragment);
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;//from  w  w  w. ja v  a 2s .  c  o m
    path = i.getStringExtra("path");

    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                MainFragment m = ((MainFragment) getFragment().getTab());
                m.loadlist(path, false, OpenMode.FILE);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if (i.getCategories() != null && i.getCategories().contains(CLOUD_AUTHENTICATOR_GDRIVE)) {

        // we used an external authenticator instead of APIs. Probably for Google Drive
        CloudRail.setAuthenticationResponse(intent);

    } else if ((openProcesses = i.getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false))) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer(), KEY_INTENT_PROCESS_VIEWER);
        //   transaction.addToBackStack(null);
        selectedStorage = SELECT_102;
        openProcesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null) {
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }

        if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                if (sharedPref.getString(KEY_PREF_OTG, null) == null) {
                    sharedPref.edit().putString(KEY_PREF_OTG, VALUE_PREF_OTG_NULL).apply();
                    refreshDrawer();
                }
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                sharedPref.edit().putString(KEY_PREF_OTG, null).apply();
                refreshDrawer();
            }
        }
    }
}