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:Main.java

public static void removeFragment(Activity activity, Fragment fragment) {
    if (activity != null) {
        try {/*  ww w  .  j a  va  2  s  .c o m*/
            FragmentManager fragmentManager = activity.getFragmentManager();
            fragmentManager.executePendingTransactions();
            if (fragment.isAdded()) {
                FragmentTransaction ft = fragmentManager.beginTransaction();
                ft.remove(fragment);
                ft.commitAllowingStateLoss();
                fragmentManager.executePendingTransactions();
            }
        } catch (Exception e) {
        }
    }
}

From source file:Main.java

public static void removeDialogFragment(final String tag, final FragmentManager fragmentManager) {
    if (fragmentManager == null) {
        return;/*from   w w  w .  j  a v a 2s  . c om*/
    }
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    final Fragment prev = fragmentManager.findFragmentByTag(tag);
    if (prev != null && prev.isAdded()) {
        ft.remove(prev);
    }
    ft.commitAllowingStateLoss();
}

From source file:Main.java

public static void showDialogFragment(final DialogFragment dialog, final String tag,
        final FragmentManager fragmentManager) {
    final FragmentTransaction ft = fragmentManager.beginTransaction();
    final Fragment prev = fragmentManager.findFragmentByTag(tag);
    if (prev != null) {
        ft.remove(prev);//from  w  ww.j av  a  2  s .c  o m
    }
    ft.add(dialog, tag);
    ft.commitAllowingStateLoss();
}

From source file:cn.edu.wyu.documentviewer.RecentsCreateFragment.java

public static void show(FragmentManager fm) {
    final RecentsCreateFragment fragment = new RecentsCreateFragment();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    mFragmentManager = getFragmentManager();

    setContentView(R.layout.activity_main);

    if (null != savedInstanceState) {
        return;//from ww w . j  a v  a2s  .  c  o m
    }

    FragmentTransaction ft = mFragmentManager.beginTransaction();

    ft.add(android.R.id.content, EndPointConfigFragment.newFragment(), EndPointConfigFragment.TAG);
    ft.commitAllowingStateLoss();
}

From source file:com.android.settings.applications.BackgroundCheckSummary.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // initialize the inflater
    mInflater = inflater;/*from   w  w  w  .  jav  a  2  s  .  c  om*/

    View rootView = mInflater.inflate(R.layout.background_check_summary, container, false);

    // We have to do this now because PreferenceFrameLayout looks at it
    // only when the view is added.
    if (container instanceof PreferenceFrameLayout) {
        ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true;
    }

    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    ft.add(R.id.appops_content, new AppOpsCategory(AppOpsState.RUN_IN_BACKGROUND_TEMPLATE, true), "appops");
    ft.commitAllowingStateLoss();

    return rootView;
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    mFragmentManager = getFragmentManager();

    IntentFilter filter = new IntentFilter();
    filter.addAction(Util.ACTION_SHOW_LOGIN_PAGE);
    filter.addAction(Util.ACTION_SHOW_LOGGED_IN_PAGE);

    mLocalBroadcastManager.registerReceiver(mLocalBroadcastReceiver, filter);

    setContentView(R.layout.activity_main);

    if (null != savedInstanceState) {
        return;//from   w w w.j a v  a  2s  .co m
    }

    FragmentTransaction ft = mFragmentManager.beginTransaction();

    ft.add(android.R.id.content, LoginFragment.newFragment(), LoginFragment.TAG);
    ft.commitAllowingStateLoss();
}

From source file:com.google.android.apps.forscience.whistlepunk.devicemanager.ManageDevicesActivity.java

private void setFragment() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    Fragment fragment;// w ww  .  ja va 2  s. c o  m
    if (adapter.isEnabled() && ScanDisabledFragment.hasScanPermission(this)) {
        mManageFragment = new ManageDevicesFragment();
        fragment = mManageFragment;
    } else {
        fragment = new ScanDisabledFragment();
        mManageFragment = null;
    }
    Bundle args = new Bundle();
    args.putString(EXTRA_EXPERIMENT_ID, getIntent().getStringExtra(EXTRA_EXPERIMENT_ID));
    fragment.setArguments(args);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.fragment, fragment);
    ft.commitAllowingStateLoss();
}

From source file:ca.farrelltonsolar.uicomponents.TabStripAdapter.java

public void removeTab(Class<?> fragmentClass) {
    int position = 0;
    for (TabInfo ti : tabs) {
        if (ti.mClass.equals(fragmentClass)) {
            tabs.remove(position);/*  w  ww.ja v a2 s .c o  m*/
            break;
        }
        position++;
    }
    String tag = makeFragmentName(viewPager.getId(), getItemId(position));
    Fragment oldFragment = fragmentManager.findFragmentByTag(tag);
    if (oldFragment != null) {
        //        remove it
        destroyItem(null, position, oldFragment);
        finishUpdate(null);
        viewPager.removeView(oldFragment.getView());
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.remove(oldFragment);
        transaction.commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
}

From source file:com.songnick.blogdemo.NetEaseDemo_Activity.java

private void addContentLayout() {

    FragmentManager fm = getFragmentManager();

    FragmentTransaction ft = fm.beginTransaction();

    ft.add(R.id.content_frame, new NetEaseDemo_Fragment());
    ft.commitAllowingStateLoss();
}