Example usage for android.app FragmentManager executePendingTransactions

List of usage examples for android.app FragmentManager executePendingTransactions

Introduction

In this page you can find the example usage for android.app FragmentManager executePendingTransactions.

Prototype

public abstract boolean executePendingTransactions();

Source Link

Document

After a FragmentTransaction is committed with FragmentTransaction#commit FragmentTransaction.commit() , it is scheduled to be executed asynchronously on the process's main thread.

Usage

From source file:Main.java

public static void removeFragment(Activity activity, Fragment fragment) {
    if (activity != null) {
        try {//from ww w  .  j  av a  2s  .  com
            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:org.onepf.opfiab.opfiab_uitest.tests.ui.UnifiedFragmentHelperTest.java

private static Object createFragment(boolean isSupport, Activity activity, Instrumentation instrumentation,
        int color) throws InterruptedException {
    final Object fragment;
    if (isSupport) {
        fragment = SupportTestFragment.getInstance(color);
        final android.support.v4.app.FragmentManager supportFragmentManager = ((FragmentActivity) activity)
                .getSupportFragmentManager();
        supportFragmentManager.beginTransaction()
                .replace(R.id.content, (android.support.v4.app.Fragment) fragment, FRAGMENT_TAG).commit();
        instrumentation.runOnMainSync(new Runnable() {
            @Override//from w  w  w .j a  v  a  2s .c om
            public void run() {
                supportFragmentManager.executePendingTransactions();
            }
        });
    } else {
        fragment = TestFragment.getInstance(color);
        final FragmentManager fragmentManager = activity.getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content, (Fragment) fragment, FRAGMENT_TAG).commit();
        instrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                fragmentManager.executePendingTransactions();
            }
        });
    }
    Thread.sleep(WAIT_INIT);
    return fragment;
}

From source file:com.commonsware.android.pagercolumns.MainActivity.java

private void populateColumn(FragmentManager fm, FragmentTransaction ft, SamplePagerAdapter adapter,
        int position, int slot) {
    EditorFragment f = adapter.getExistingFragment(position);

    if (f == null) {
        f = adapter.createFragment(buildTitle(position));
    } else {//from  w  w w.j  a va 2 s .  c  o  m
        fm.beginTransaction().remove(f).commit();
        fm.executePendingTransactions();
    }

    ft.add(slot, f, buildTag(position));
}

From source file:com.notriddle.budget.EnvelopesActivity.java

public void switchFragment(Class<?> cls, String name, Bundle args) {
    Fragment frag = Fragment.instantiate(this, cls.getName(), args);
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, frag).addToBackStack(name)
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    fragmentManager.executePendingTransactions();
    configureFragment(frag);//from ww  w  .ja  v a 2  s .c om
}

From source file:com.notriddle.budget.EnvelopesActivity.java

public void topFragment(Class<?> cls, int transition, Bundle args) {
    Fragment frag = Fragment.instantiate(this, cls.getName(), args);
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentManager.beginTransaction().replace(R.id.content_frame, frag).setTransition(transition).commit();
    fragmentManager.executePendingTransactions();
    configureFragment(frag);/*from  w w  w  .  j  av a 2s .com*/
}

From source file:org.peterbaldwin.vlcremote.app.PickServerActivity.java

@SuppressWarnings("unchecked")
public <T extends android.app.Fragment> T findOrReplaceFragment(int res, String tag, Class<T> fragmentClass) {
    try {//from   ww w .java 2 s  . c  om
        FragmentManager fm = getFragmentManager();
        T fragment = (T) fm.findFragmentByTag(tag);
        if (fragment == null) {
            fragment = fragmentClass.newInstance();
            FragmentTransaction fragmentTransaction = fm.beginTransaction();
            fragmentTransaction.replace(res, fragment, tag);
            fragmentTransaction.commit();
            fm.executePendingTransactions();
        }
        return fragment;
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(e);
    }
}

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

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {/*from   ww  w . j a v  a2s.  c o  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:com.ternup.caddisfly.fragment.DetailsFragment.java

private void goBack() {
    FragmentManager fm = getFragmentManager();
    try {//www . j  av  a  2s.  c o  m
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
            fm.executePendingTransactions();
        } else {
            Fragment fragment = new HomeFragment();
            FragmentManager fragmentManager = getFragmentManager();
            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:com.docd.purefm.ui.activities.BrowserPagerActivity.java

@Override
protected void onPause() {
    super.onPause();
    final FragmentManager fm = getFragmentManager();
    final Fragment f = fm.findFragmentByTag(TAG_DIALOG);
    if (f != null) {
        fm.beginTransaction().remove(f).commit();
        fm.executePendingTransactions();
    }/*from   w  ww.  j av a  2 s .c o  m*/
}

From source file:net.sf.aria2.MainActivity.java

@TargetApi(HONEYCOMB)
private void reselectFragment() {
    final Intent intent = getIntent();

    if (intent != null && intent.hasExtra(Config.EXTRA_FROM_NF)) {
        final String displayedFragment = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
        if (displayedFragment != null) {
            final FragmentManager fm = getFragmentManager();
            fm.executePendingTransactions();

            if (displayedFragment.equals(lastChosenFragment))
                return;

            final Header headerToSelect = onGetInitialHeader();

            startPreferencePanel(displayedFragment, headerToSelect.fragmentArguments, headerToSelect.titleRes,
                    headerToSelect.title, null, 0);
        }/*ww  w  .j av  a  2  s  .  co  m*/
    }
}