Example usage for android.app FragmentTransaction commitAllowingStateLoss

List of usage examples for android.app FragmentTransaction commitAllowingStateLoss

Introduction

In this page you can find the example usage for android.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:co.taqat.call.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();//from w ww  .j  av  a  2 s. c om
        } else {
            hideStatusBar();
        }
    }
    emptyFragment = false;
    LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);

    FragmentTransaction transaction = getFragmentManager().beginTransaction();

    if (newFragmentType == FragmentsAvailable.EMPTY) {
        ll.setVisibility(View.VISIBLE);
        emptyFragment = true;
        transaction.replace(R.id.fragmentContainer2, newFragment);
        transaction.commitAllowingStateLoss();
        getFragmentManager().executePendingTransactions();
    } else {
        if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) {
            ll.setVisibility(View.VISIBLE);

            if (newFragmentType == FragmentsAvailable.CONTACT_EDITOR) {
                transaction.addToBackStack(newFragmentType.toString());
            }
            transaction.replace(R.id.fragmentContainer2, newFragment);
        } else {
            if (newFragmentType == FragmentsAvailable.EMPTY) {
                ll.setVisibility(View.VISIBLE);
                transaction.replace(R.id.fragmentContainer2, new EmptyFragment());
                emptyFragment = true;
            }

            if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.ABOUT
                    || newFragmentType == FragmentsAvailable.SETTINGS
                    || newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) {
                ll.setVisibility(View.GONE);
            } else {
                ll.setVisibility(View.VISIBLE);
                transaction.replace(R.id.fragmentContainer2, new EmptyFragment());
            }

            /*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();
        getFragmentManager().executePendingTransactions();

        currentFragment = newFragmentType;
        if (newFragmentType == FragmentsAvailable.DIALER || newFragmentType == FragmentsAvailable.SETTINGS
                || newFragmentType == FragmentsAvailable.CONTACTS_LIST
                || newFragmentType == FragmentsAvailable.CHAT_LIST
                || newFragmentType == FragmentsAvailable.HISTORY_LIST) {
            try {
                getFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
            } catch (java.lang.IllegalStateException e) {

            }
        }
        fragmentsHistory.add(currentFragment);
    }
}

From source file:com.android.deskclock.AlarmClockFragment.java

private void showLabelDialog(final Alarm alarm) {
    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment prev = getFragmentManager().findFragmentByTag("label_dialog");
    if (prev != null) {
        ft.remove(prev);/*from  w  w w.  j av  a 2  s.c o  m*/
    }
    /// M:If the LabelEditDialog Existed,do not create again
    //ft.addToBackStack(null);
    /// M:Don't need use the method ft.commit(), because it may cause IllegalStateException
    final LabelDialogFragment newFragment = LabelDialogFragment.newInstance(alarm, alarm.label, getTag());
    ft.add(newFragment, "label_dialog");
    ft.commitAllowingStateLoss();
    getFragmentManager().executePendingTransactions();
}

From source file:com.android.dialer.DialtactsFragment.java

/**
 * @author bbk wangchunhe/*from   w  ww .j  a v a 2  s .  co  m*/
 * @Date 2016/07/15
 * show CallLogFragment of filterType
 * @param filterType
 */
private void showCallLogFragment(int filterType) {

    final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    if (mCalllogList != null) {
        transaction.remove(mCalllogList);
    }

    mCalllogList = new CallLogFragment(filterType);
    transaction.add(R.id.dialtacts_frame, mCalllogList, "mCalllogList");
    mCalllogList.setRecyclerViewChangedImpl(mRecyclerViewChangedImpl);
    transaction.show(mCalllogList);
    transaction.commitAllowingStateLoss();

}

From source file:com.android.dialer.DialtactsFragment.java

private void showSearchFragment() {
    final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    getActivity().getActionBar().hide();
    mSearchViewShow = true;//from  w  w  w.j  a va  2 s .  co  m
    mDialpadFragment.showSearchView();
    if (mCalllogList != null) {
        //Log.e(TAG,"SHOWSearchFragment");
        transaction.hide(mCalllogList);
    }
    if (getCallLogFragment() != null) {
        transaction.hide(getCallLogFragment());
    }
    transaction.commitAllowingStateLoss();
}

From source file:com.android.dialer.DialtactsFragment.java

/**
 *?/*from   w  w w. ja v  a 2 s  . co m*/
 **/
private void addCallLogFragmentInList() {
    final FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    if (getCallLogFragment() == null) {
        mCalllogList = null;
        mCalllogList = new CallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL);
        transaction.add(R.id.dialtacts_frame, mCalllogList, "mCalllogList");
    } else {
        mCalllogList = (CallLogFragment) getCallLogFragment();
    }
    mCalllogList.setRecyclerViewChangedImpl(mRecyclerViewChangedImpl);
    transaction.show(mCalllogList);
    transaction.commitAllowingStateLoss();
}

From source file:com.evandroid.musica.MainLyricActivity.java

public void updateLyricsFragment(int outAnim, int inAnim, boolean transition, Lyrics lyrics) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager()
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(inAnim, outAnim, inAnim, outAnim);
    Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    if (lyricsViewFragment != null && lyricsViewFragment.getView() != null) {
        SharedPreferences preferences = getSharedPreferences("current_music", Context.MODE_PRIVATE);
        String artist = preferences.getString("artist", null);
        String track = preferences.getString("track", null);
        if (lyrics.isLRC()
                && !(lyrics.getOriginalArtist().equals(artist) && lyrics.getOriginalTrack().equals(track))) {
            LrcView parser = new LrcView(this, null);
            parser.setOriginalLyrics(lyrics);
            parser.setSourceLrc(lyrics.getText());
            lyrics = parser.getStaticLyrics();
        }/*  w  w w. j av  a  2 s . c  o  m*/
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
    } else {
        Bundle lyricsBundle = new Bundle();
        try {
            lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);
        if (!(activeFragment instanceof LyricsViewFragment) && activeFragment != null)
            fragmentTransaction.hide(activeFragment).add(R.id.main_fragment_container, lyricsViewFragment,
                    LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(R.id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.android.mms.ui.MessageUtils.java

public static void showErrorDialog(Activity activity, int titleId, int messageId, int mediaTypeIdForTitle,
        int mediaTypeIdForMsg) {
    /** M:/*from ww  w  .j a v a2  s . co  m*/
    the original code is replaced by the following code.
    the original code has a bug, JE may happen.
    the case is when the activity is destoried by some reason(ex:change language),
    when dismiss the dialog, it may be throw a JE. see 298363.
    */
    ErrorDialog errDialog = ErrorDialog.newInstance(titleId, messageId, mediaTypeIdForTitle, mediaTypeIdForMsg);
    try {
        errDialog.show(activity.getFragmentManager(), "errDialog");
    } catch (IllegalStateException e) {
        try {
            MmsLog.d(TAG, "showErrorDialog catch IllegalStateException." + e);
            FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
            transaction.add(errDialog, "errDialog");
            transaction.commitAllowingStateLoss();
        } catch (Exception e2) {
            MmsLog.e(TAG, "showErrorDialog commitAllowingStateLoss catch Exception." + e2);
        }
        return;
    }
}

From source file:com.android.settings.HWSettings.java

private void createFragments() {
    DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

    this.mViewPager = ((ViewPager) findViewById(R.id.tab_pager));
    this.mPagerAdapter = new SettingsPagerAdapter();
    this.mViewPager.setAdapter(this.mPagerAdapter);
    SettingsPageChangeListener localSettingsPageChangeListener = new SettingsPageChangeListener();
    this.mViewPager.setOnPageChangeListener(localSettingsPageChangeListener);
    this.mFragmentManager = getFragmentManager();
    FragmentTransaction localFragmentTransaction = this.mFragmentManager.beginTransaction();
    Fragment localFragment1 = this.mFragmentManager
            .findFragmentByTag("com.android.settings.HWAllSettingsFragment");
    if (localFragment1 != null)
        localFragmentTransaction.remove(localFragment1);
    Fragment localFragment2 = this.mFragmentManager
            .findFragmentByTag("com.android.settings.HWGeneralSettingsFragment");
    if (localFragment2 != null)
        localFragmentTransaction.remove(localFragment2);
    Log.d("dingjingliang", "createFragments: curTabIndex" + curTabIndex);
    this.mGeneralSettingsFragment = new HWGeneralSettingsFragment(mAuthenticatorHelper, dpm);
    localFragmentTransaction.add(R.id.tab_pager, this.mGeneralSettingsFragment,
            "com.android.settings.HWGeneralSettingsFragment");
    localFragmentTransaction.hide(this.mGeneralSettingsFragment);
    this.mAllSettingsFragment = new HWAllSettingsFragment(mAuthenticatorHelper, dpm);
    localFragmentTransaction.add(R.id.tab_pager, this.mAllSettingsFragment,
            "com.android.settings.HWAllSettingsFragment");
    localFragmentTransaction.hide(this.mAllSettingsFragment);
    localFragmentTransaction.commitAllowingStateLoss();
    this.mFragmentManager.executePendingTransactions();
}

From source file:com.geecko.QuickLyric.MainActivity.java

public void updateLyricsFragment(int outAnim, int inAnim, boolean transition, Lyrics lyrics) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager()
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(inAnim, outAnim, inAnim, outAnim);
    Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    if (lyricsViewFragment != null && lyricsViewFragment.getView() != null) {
        SharedPreferences preferences = getSharedPreferences("current_music", Context.MODE_PRIVATE);
        String artist = preferences.getString("artist", null);
        String track = preferences.getString("track", null);
        if (lyrics.isLRC()
                && !(lyrics.getOriginalArtist().equals(artist) && lyrics.getOriginalTrack().equals(track))) {
            LrcView parser = new LrcView(this, null);
            parser.setOriginalLyrics(lyrics);
            parser.setSourceLrc(lyrics.getText());
            lyrics = parser.getStaticLyrics();
        }//from   w  ww .java 2 s.  c om
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
        showRefreshFab(true);
        lyricsViewFragment.expandToolbar();
    } else {
        Bundle lyricsBundle = new Bundle();
        try {
            lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);
        if (!(activeFragment instanceof LyricsViewFragment) && activeFragment != null)
            fragmentTransaction.hide(activeFragment).add(id.main_fragment_container, lyricsViewFragment,
                    LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:co.taqat.call.LinphoneActivity.java

private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType,
        boolean withoutAnimation) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();
    /*/*from   ww  w  . j  a  v  a2  s  . com*/
          if (!withoutAnimation && 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);
             }
          }*/

    if (newFragmentType != FragmentsAvailable.DIALER && newFragmentType != FragmentsAvailable.CONTACTS_LIST
            && newFragmentType != FragmentsAvailable.CHAT_LIST
            && newFragmentType != FragmentsAvailable.HISTORY_LIST) {
        transaction.addToBackStack(newFragmentType.toString());
    } else {
        while (fm.getBackStackEntryCount() > 0) {
            fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    }

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

    currentFragment = newFragmentType;
}