Example usage for android.support.v4.app FragmentManager executePendingTransactions

List of usage examples for android.support.v4.app FragmentManager executePendingTransactions

Introduction

In this page you can find the example usage for android.support.v4.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:org.lol.reddit.activities.MainActivity.java

public void onPostCommentsSelected(final RedditPreparedPost post) {

    if (twoPane) {

        commentListingController = new CommentListingController(PostCommentListingURL.forPostId(post.idAlone),
                this);

        if (isMenuShown) {

            final FragmentManager fm = getSupportFragmentManager();

            fm.beginTransaction().remove(postListingFragment).commit();
            fm.executePendingTransactions();

            final FragmentTransaction transaction = fm.beginTransaction();
            commentListingFragment = commentListingController.get(false);
            transaction.replace(R.id.main_left_frame, postListingFragment); // TODO fix this...
            transaction.replace(R.id.main_right_frame, commentListingFragment);

            mainMenuFragment = null;//from ww  w  . j  ava 2  s.c  o m
            isMenuShown = false;

            transaction.commit();

            invalidateOptionsMenu();

        } else {
            requestRefresh(RefreshableFragment.COMMENTS, false);
        }

    } else {
        LinkHandler.onLinkClicked(this, PostCommentListingURL.forPostId(post.idAlone).toString(), false);
    }
}

From source file:com.kkbox.toolkit.app.KKFragment.java

public void switchToFragment(Fragment fragment, Bundle arguments) {
    if (arguments != null) {
        fragment.setArguments(arguments);
    }/*ww w. j  a  va  2  s.  co  m*/
    FragmentTransaction fragmentTransaction;
    FragmentManager fragmentManager;
    if (getArguments() == null || !getArguments().getBoolean("nested_in_tab", false)) {
        fragmentManager = getFragmentManager();
    } else {
        fragmentManager = getParentFragment().getFragmentManager();
    }
    fragmentTransaction = fragmentManager.beginTransaction();
    KKFragment.setAnimation(KKFragment.AnimationType.PUSH);
    fragmentTransaction.replace(R.id.sub_fragment, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
    fragmentManager.executePendingTransactions();
}

From source file:name.gumartinm.weather.information.activity.MapActivity.java

private void removeButtonsFragment() {
    final FragmentManager fm = this.getSupportFragmentManager();
    final Fragment buttonsFragment = fm.findFragmentByTag(BUTTONS_FRAGMENT_TAG);
    if (buttonsFragment != null) {
        final FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.remove(buttonsFragment).commit();
        fm.executePendingTransactions();
    }/*from  w w w  .  ja v  a 2s . c o m*/
}

From source file:name.gumartinm.weather.information.activity.MapActivity.java

private void removeProgressFragment() {
    final FragmentManager fm = this.getSupportFragmentManager();
    final Fragment progressFragment = fm.findFragmentByTag(PROGRESS_FRAGMENT_TAG);
    if (progressFragment != null) {
        final FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.remove(progressFragment).commit();
        fm.executePendingTransactions();
    }/*from   w w w.j  a v  a  2 s.  com*/
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    instance = this;
    //        Pull using: adb pull /sdcard/RHCareerFairLayoutTrace.trace "D:\1. Work\Workspaces\Java Workspace\RHCareerFairLayout\android\RHCareerFairLayout"
    //        Debug.startMethodTracing("RHCareerFairLayoutTrace");

    setContentView(R.layout.activity_main);

    DBManager.setupDBAdapterIfNeeded(this);

    // Setup search, without suggestions, and defaulting to last searched string.
    search = (SearchBox) findViewById(R.id.searchbox);
    search.enableVoiceRecognition(this);
    search.setSearchWithoutSuggestions(true);
    search.setSearchString(getSearchString());

    // Setup toolbar
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from www  . j a  va2  s . c om*/

    // Setup title
    Term term = DBManager.getTerm();
    if (term == null) {
        reloadData();
        return;
    } else {
        ((TextView) findViewById(R.id.main_txt_title))
                .setText(getString(R.string.career_fair_format, term.getQuarter(), term.getYear()));
    }

    // Setup parent fragment with tabPager
    FragmentManager fm = getSupportFragmentManager();
    if (fm.findFragmentByTag(RHCareerFairLayout.PARENT_FRAGMENT_TAG) == null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.main_frg_body, new VPParentFragment(), RHCareerFairLayout.PARENT_FRAGMENT_TAG);
        ft.commit();
        fm.executePendingTransactions();
    }
}

From source file:com.erevacation.challenge.ui.base.navigator.BaseNavigator.java

private void replaceFragmentInternal(FragmentManager fm, @IdRes int containerId, Fragment fragment,
        String fragmentTag, Bundle args, boolean addToBackStack, String backStackTag) {

    if (args != null) {
        fragment.setArguments(args);//from  ww  w  . j  a  v  a  2s  .  com
    }

    if (addToBackStack) {
        Fragment replacedFragment = fm.findFragmentById(containerId);
        if (replacedFragment != null) {
            fm.saveFragmentInstanceState(replacedFragment);
        }

        mFragmentBackStackAnimations.apply(fm.beginTransaction()).add(containerId, fragment, fragmentTag)
                .addToBackStack(backStackTag).commit();
        fm.executePendingTransactions();
    } else {
        mFragmentAnimations.apply(fm.beginTransaction()).replace(containerId, fragment, fragmentTag)
                .commitNow();
    }
}

From source file:com.erevacation.reactiveanimations.ui.base.navigator.BaseNavigator.java

private void replaceFragmentInternal(FragmentManager fm, @IdRes int containerId, Fragment fragment,
        String fragmentTag, Bundle args, boolean addToBackStack, String backStackTag) {

    if (args != null) {
        fragment.setArguments(args);/*w w  w.  j  av a 2  s. co  m*/
    }

    if (addToBackStack) {
        Fragment replacedFragment = fm.findFragmentById(containerId);
        if (replacedFragment != null) {
            fm.saveFragmentInstanceState(replacedFragment);
        }

        mFragmentBackStackAnimations.apply(fm.beginTransaction()).replace(containerId, fragment, fragmentTag)
                .addToBackStack(backStackTag).commit();
        fm.executePendingTransactions();
    } else {
        mFragmentAnimations.apply(fm.beginTransaction()).replace(containerId, fragment, fragmentTag)
                .commitNow();
    }
}

From source file:com.github.michalbednarski.intentslab.valueeditors.framework.EditorLauncher.java

EditorLauncher(final Fragment ownerFragment) {
    // Verify interface
    if (BuildConfig.DEBUG && !(ownerFragment instanceof EditorLauncherCallback
            || ownerFragment instanceof EditorLauncherCallbackDelegate)) {
        throw new AssertionError("Fragment doesn't implement callback interface");
    }/* w ww  .j  a  v  a2 s.  co m*/

    // Find existing helper fragment
    FragmentManager fragmentManager = ownerFragment.getChildFragmentManager();
    mHelperFragment = (HelperFragment) fragmentManager.findFragmentByTag(TAG_HELPER_FRAGMENT);

    // Create it if it doesn't exist
    if (mHelperFragment == null) {
        mHelperFragment = new HelperFragment();
        fragmentManager.beginTransaction().add(mHelperFragment, TAG_HELPER_FRAGMENT).commit();
        fragmentManager.executePendingTransactions();

        // If our process has been restarted fragment manager won't
        // use fragment we added above.
        // Add owner (parent) fragment to pending initializations and let it
        // associate with us in it's onCreate
        sPendingInitializations.put(ownerFragment, this);
        (new Handler()).post(new Runnable() {
            @Override
            public void run() {
                sPendingInitializations.remove(ownerFragment);
            }
        });
    }

    // Assign to helper fragment
    mHelperFragment.mEditorLauncher = this;
}

From source file:name.gumartinm.weather.information.activity.MapActivity.java

/*****************************************************************************************************
 *
 *                      MapProgressFragment
 * I am not using fragment transactions in the right way. But I do not know other way for doing what I am doing.
  * Android sucks./*from  ww w .ja  va 2  s.c o  m*/
  *
  * "Avoid performing transactions inside asynchronous callback methods." :(
  * see: http://stackoverflow.com/questions/16265733/failure-delivering-result-onactivityforresult
  * see: http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html
  * How do you do what I am doing in a different way without using fragments?
 *****************************************************************************************************/

private void addProgressFragment(final double latitude, final double longitude) {
    final Fragment progressFragment = new MapProgressFragment();
    progressFragment.setRetainInstance(true);
    final Bundle args = new Bundle();
    args.putDouble("latitude", latitude);
    args.putDouble("longitude", longitude);
    progressFragment.setArguments(args);

    final FragmentManager fm = this.getSupportFragmentManager();
    final FragmentTransaction fragmentTransaction = fm.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.weather_map_enter_progress,
            R.anim.weather_map_exit_progress);
    fragmentTransaction.add(R.id.weather_map_buttons_container, progressFragment, PROGRESS_FRAGMENT_TAG)
            .commit();
    fm.executePendingTransactions();
}

From source file:com.nijie.samples.facebookfoo.FacebookFooMainActivity.java

private void showListPostsFragment(ListPostsFragment fragment) {
    FragmentManager fm = getSupportFragmentManager();
    fm.beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit();

    controlsContainer.setVisibility(View.GONE);

    // We want the fragment fully created so we can use it immediately.
    fm.executePendingTransactions();

}