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:com.geotrackin.gpslogger.GpsMainActivity.java

/**
 * Handles dropdown selection//w w  w  .  jav a  2s.co  m
 */
@Override
public boolean onNavigationItemSelected(int position, long id) {

    tracer.debug("Changing main view: " + String.valueOf(position));
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt("dropdownview", position);
    editor.commit();

    FragmentTransaction transaction = fragmentManager.beginTransaction();

    switch (position) {
    case 0:
        transaction.replace(R.id.container, GpsSimpleViewFragment.newInstance());
        break;
    case 1:
        transaction.replace(R.id.container, GpsDetailedViewFragment.newInstance());
        break;
    default:
    case 2:
        transaction.replace(R.id.container, GpsBigViewFragment.newInstance());
        break;
    }
    transaction.commitAllowingStateLoss();

    return true;
}

From source file:com.android.contacts.activities.DialtactsActivity.java

/**
 * Add search fragment.  Note this is called during onLayout, so there's some restrictions,
 * such as executePendingTransaction can't be used in it.
 *///  w w  w  .ja  va2 s.c om
private void addSearchFragment() {
    // In order to take full advantage of "fragment deferred start", we need to create the
    // search fragment after all other fragments are created.
    // The other fragments are created by the ViewPager on the first onMeasure().
    // We use the first onLayout call, which is after onMeasure().

    // Just return if the fragment is already created, which happens after configuration
    // changes.
    if (mSearchFragment != null)
        return;

    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment searchFragment = new PhoneNumberPickerFragment();

    searchFragment.setUserVisibleHint(false);
    ft.add(R.id.dialtacts_frame, searchFragment);
    ft.hide(searchFragment);
    ft.commitAllowingStateLoss();
}

From source file:com.tct.mail.ui.OnePaneController.java

@Override
protected void showConversation(Conversation conversation) {
    super.showConversation(conversation);
    // TS: tao.gan 2015-09-21 EMAIL FEATURE-559893 ADD_S
    //we change from ConversationListFragment to ConversationViewFragment, should let the toolbar show
    animateShow(null);/*from  www  .  ja va 2s  . c  o m*/
    // TS: tao.gan 2015-09-21 EMAIL FEATURE-559893 ADD_E
    mConversationListVisible = false;
    if (conversation == null) {
        transitionBackToConversationListMode();
        return;
    }
    disableCabMode();
    if (ConversationListContext.isSearchResult(mConvListContext)) {
        mViewMode.enterSearchResultsConversationMode();
    } else {
        mViewMode.enterConversationMode();
    }
    final FragmentManager fm = mActivity.getFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    // Switching to conversation view is an incongruous transition:
    // we are not replacing a fragment with another fragment as
    // usual. Instead, reveal the heretofore inert conversation
    // ViewPager and just remove the previously visible fragment
    // e.g. conversation list, or possibly label list?).
    final Fragment f = fm.findFragmentById(R.id.content_pane);
    // FragmentManager#findFragmentById can return fragments that are not added to the activity.
    // We want to make sure that we don't attempt to remove fragments that are not added to the
    // activity, as when the transaction is popped off, the FragmentManager will attempt to
    // readd the same fragment twice
    if (f != null && f.isAdded()) {
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.remove(f);
        ft.commitAllowingStateLoss();
        //TS: jin.dong 2015-8-28 EMAIL BUGFIX-1075110 MOD_S
        try {
            fm.executePendingTransactions();
        } catch (IllegalArgumentException e) {
            LogUtils.d(LOG_TAG, e, "IllegalArgumentException occurred");
        }
        //TS: jin.dong 2015-8-28 EMAIL BUGFIX-1075110 MOD_E
    }
    mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */);
    onConversationVisibilityChanged(true);
    onConversationListVisibilityChanged(false);
}

From source file:com.frostwire.android.gui.activities.MainActivity.java

private void hideFragments() {
    try {/*from  ww w .  j a  v a2s .  c  o m*/
        getFragmentManager().executePendingTransactions();
    } catch (Throwable t) {
        LOG.warn(t.getMessage(), t);
    }
    FragmentTransaction tx = getFragmentManager().beginTransaction();
    tx.hide(search).hide(library).hide(transfers);
    try {
        tx.commit();
    } catch (IllegalStateException e) {
        // if not that we can do a lot here, since the root of the problem
        // is the multiple entry points to MainActivity, just let it run
        // a possible inconsistent (but probably right) version.
        // in the future with a higher API, commitNow should be considered
        LOG.warn("Error running commit in fragment transaction, using weaker option", e);
        try {
            tx.commitAllowingStateLoss();
        } catch (IllegalStateException e2) {
            // \_()_/
            LOG.warn(
                    "Error running commit in fragment transaction, weaker option also failed (commit already called - mCommited=true)",
                    e2);
        }
    }
}

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

private void replaceFragmentVideoByAudio() {
    audioCallFragment = new CallAudioFragment();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.fragmentContainer, audioCallFragment);
    try {//  w ww .  j  av a2  s  .c o  m
        transaction.commitAllowingStateLoss();
    } catch (Exception e) {
    }
}

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

private void replaceFragmentAudioByVideo() {
    //      Hiding controls to let displayVideoCallControlsIfHidden add them plus the callback
    videoCallFragment = new CallVideoFragment();

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.fragmentContainer, videoCallFragment);
    try {//ww  w.ja v  a  2s.  c om
        transaction.commitAllowingStateLoss();
    } catch (Exception e) {
    }
}

From source file:com.crearo.gpslogger.GpsMainActivity.java

private void loadFragmentView(int position) {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();

    switch (position) {
    default:/*  w ww.  ja  v  a2 s  .c o m*/
    case 0:
        transaction.replace(R.id.container, GpsSimpleViewFragment.newInstance());
        break;
    case 1:
        transaction.replace(R.id.container, GpsDetailedViewFragment.newInstance());
        break;
    case 2:
        transaction.replace(R.id.container, GpsBigViewFragment.newInstance());
        break;
    case 3:
        transaction.replace(R.id.container, GpsLogViewFragment.newInstance());
        break;

    }
    transaction.commitAllowingStateLoss();
}

From source file:com.samsung.msca.samsungvr.sampleapp.LoggedInFragment.java

private void selectItem(int position) {
    if (null == mUser || position == mCurrentSelection) {
        return;/*from w ww .  ja v  a2 s  .  com*/
    }
    mCurrentSelection = position;
    mDrawerList.setItemChecked(position, true);
    mDrawerLayout.closeDrawer(mDrawerList);

    Bundle args = null;
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    Fragment fragment = null;
    String tag = null;

    switch (position) {
    case 1: /* Create live event */

        tag = CreateLiveEventFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = CreateLiveEventFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 2: /* List live events */

        tag = ListLiveEventsFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = ListLiveEventsFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 3: /* Upload video */

        tag = UploadVideoFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = UploadVideoFragment.newFragment();
        }
        args = new Bundle();
        args.putString(PARAM_USER, mUser.getUserId());
        break;

    case 4: /* Get user by session id */

        tag = GetUserBySessionInfoFragment.TAG;
        fragment = mFragmentManager.findFragmentByTag(tag);
        if (null == fragment) {
            fragment = GetUserBySessionInfoFragment.newFragment();
        }
        break;

    }
    if (null != fragment && !fragment.isVisible()) {
        if (null != args) {
            fragment.setArguments(args);
        }
        ft.replace(R.id.content_frame, fragment, tag);
        ft.commitAllowingStateLoss();
    }
}

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

@Override
public void onListFragmentScrollStateChange(int scrollState) {
    if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
        Log.e(TAG, "onListFragmentScrollStateChange");
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.hide(mCalllogList);/*w  ww .j  a v  a  2 s.c o  m*/
        transaction.commitAllowingStateLoss();
        hideDialpadFragment(true, false);
        DialerUtils.hideInputMethod(mParentLayout);
    }
}

From source file:com.hijacker.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.reset:
        stop(PROCESS_AIRODUMP);//  w w w .ja  va 2 s. c o m
        Tile.clear();
        Tile.onCountsChanged();
        Airodump.startClean();
        return true;

    case R.id.stop_run:
        if (Airodump.isRunning())
            stop(PROCESS_AIRODUMP);
        else
            Airodump.start();
        return true;

    case R.id.stop_aireplay:
        stop(PROCESS_AIREPLAY);
        return true;

    case R.id.filter:
        new FiltersDialog().show(mFragmentManager, "FiltersDialog");
        return true;

    case R.id.settings:
        if (currentFragment != FRAGMENT_SETTINGS) {
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            ft.replace(R.id.fragment1, new SettingsFragment());
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            ft.addToBackStack(null);
            ft.commitAllowingStateLoss();
        }
        return true;

    case R.id.export:
        new ExportDialog().show(mFragmentManager, "ExportDialog");
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}