Java Code Examples for android.support.v4.app.fragmentmanager#executePendingTransactions()
The following examples show how to use
android.support.v4.app.fragmentmanager#executePendingTransactions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxFacebookAuth.java From RxSocialAuth with Apache License 2.0 | 7 votes |
/** * Get instance of RxFacebookAuthFragment * * @return a RxFacebookAuthFragment */ private RxFacebookAuthFragment getRxFacebookAuthFragment(Builder builder) { FragmentManager fragmentManager = mActivity.getSupportFragmentManager(); // prevent fragment manager already executing transaction int stackCount = fragmentManager.getBackStackEntryCount(); if( fragmentManager.getFragments() != null ) fragmentManager = fragmentManager.getFragments().get( stackCount > 0 ? stackCount-1 : stackCount ).getChildFragmentManager(); RxFacebookAuthFragment rxFacebookAuthFragment = (RxFacebookAuthFragment) fragmentManager.findFragmentByTag(RxFacebookAuthFragment.TAG); if (rxFacebookAuthFragment == null) { rxFacebookAuthFragment = RxFacebookAuthFragment.newInstance(builder); fragmentManager .beginTransaction() .add(rxFacebookAuthFragment, RxFacebookAuthFragment.TAG) .commit(); fragmentManager.executePendingTransactions(); } return rxFacebookAuthFragment; }
Example 2
Source File: ErrorDialogManager.java From KUtils with Apache License 2.0 | 6 votes |
public void onEventMainThread(ThrowableFailureEvent event) { if (!isInExecutionScope(executionScope, event)) { return; } checkLogException(event); // Execute pending commits before finding to avoid multiple error fragments being shown FragmentManager fm = getFragmentManager(); fm.executePendingTransactions(); DialogFragment existingFragment = (DialogFragment) fm.findFragmentByTag(TAG_ERROR_DIALOG); if (existingFragment != null) { // Just show the latest error existingFragment.dismiss(); } DialogFragment errorFragment = (DialogFragment) factory .prepareErrorFragment(event, finishAfterDialog, argumentsForErrorDialog); if (errorFragment != null) { errorFragment.show(fm, TAG_ERROR_DIALOG); } }
Example 3
Source File: ErrorDialogManager.java From KUtils-master with Apache License 2.0 | 6 votes |
public void onEventMainThread(ThrowableFailureEvent event) { if (!isInExecutionScope(executionScope, event)) { return; } checkLogException(event); // Execute pending commits before finding to avoid multiple error fragments being shown FragmentManager fm = getFragmentManager(); fm.executePendingTransactions(); DialogFragment existingFragment = (DialogFragment) fm.findFragmentByTag(TAG_ERROR_DIALOG); if (existingFragment != null) { // Just show the latest error existingFragment.dismiss(); } DialogFragment errorFragment = (DialogFragment) factory .prepareErrorFragment(event, finishAfterDialog, argumentsForErrorDialog); if (errorFragment != null) { errorFragment.show(fm, TAG_ERROR_DIALOG); } }
Example 4
Source File: Wizard.java From Wizard with Apache License 2.0 | 6 votes |
public boolean navigateNext() { if (!activity.isFinishing()) { FragmentManager fragmentManager = activity.getSupportFragmentManager(); int nextStep = fragmentManager.getBackStackEntryCount() + 1; if (nextStep < pages.length) { WizardPage WizardPage = pages[nextStep]; Fragment fragment = WizardPage.createFragment(); fragmentManager.beginTransaction() .addToBackStack(fragment.getClass().getName()) .setCustomAnimations(enterAnimation, exitAnimation, popEnterAnimation, popExitAnimation) .replace(containerId, fragment) .commit(); fragmentManager.executePendingTransactions(); return true; } else if (wizardListener != null) { wizardListener.onWizardFinished(); } } return false; }
Example 5
Source File: EasyResult.java From imsdk-android with MIT License | 5 votes |
private HolderFragment getHolderFragment(FragmentManager fragmentManager) { HolderFragment holderFragment = findHolderFragment(fragmentManager); if (holderFragment == null) { holderFragment = new HolderFragment(); fragmentManager .beginTransaction() .add(holderFragment, TAG) .commitAllowingStateLoss(); fragmentManager.executePendingTransactions(); } return holderFragment; }
Example 6
Source File: MainActivity.java From openshop.io-android with MIT License | 5 votes |
/** * Method creates fragment transaction and replace current fragment with new one. * * @param newFragment new fragment used for replacement. * @param transactionTag text identifying fragment transaction. */ private void replaceFragment(Fragment newFragment, String transactionTag) { if (newFragment != null) { FragmentManager frgManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = frgManager.beginTransaction(); fragmentTransaction.setAllowOptimization(false); fragmentTransaction.addToBackStack(transactionTag); fragmentTransaction.replace(R.id.main_content_frame, newFragment).commit(); frgManager.executePendingTransactions(); } else { Timber.e(new RuntimeException(), "Replace fragments with null newFragment parameter."); } }
Example 7
Source File: FragmentActionBarControlListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragmentactionbarcontrol); FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentByTag(FragmentTransitionDefaultFragment.FRAGMENT_TAG) == null) { FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.container, new FragmentActionBarControlListViewFragment(), FragmentActionBarControlListViewFragment.FRAGMENT_TAG); ft.commit(); fm.executePendingTransactions(); } }
Example 8
Source File: AbstractBarterLiActivity.java From barterli_android with Apache License 2.0 | 5 votes |
/** * Helper method to load fragments into layout * * @param containerResId The container resource Id in the content view into which to load the * fragment * @param fragment The fragment to load * @param tag The fragment tag * @param addToBackStack Whether the transaction should be addded to the backstack * @param backStackTag The tag used for the backstack tag * @param customAnimate Whether to provide a custom animation for the Fragment. If * <code>true</code>, the Fragment also needs to be annotated with a * {@linkplain li.barter.fragments.FragmentTransition} annotation which * describes the transition to perform. If <code>false</code>, will use * default fragment transition * @param remove Whether the fragment should be removed before adding it */ public void loadFragment(final int containerResId, final AbstractBarterLiFragment fragment, final String tag, final boolean addToBackStack, final String backStackTag, final boolean customAnimate, final boolean remove) { final FragmentManager fragmentManager = getSupportFragmentManager(); if (remove) { fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); fragmentManager.beginTransaction().remove(fragment).commit(); fragmentManager.executePendingTransactions(); } final FragmentTransaction transaction = fragmentManager .beginTransaction(); if (customAnimate) { final FragmentTransition fragmentTransition = fragment.getClass() .getAnnotation( FragmentTransition.class); if (fragmentTransition != null) { transaction .setCustomAnimations(fragmentTransition.enterAnimation(), fragmentTransition .exitAnimation(), fragmentTransition .popEnterAnimation(), fragmentTransition .popExitAnimation()); } } transaction.replace(containerResId, fragment, tag); if (addToBackStack) { transaction.addToBackStack(backStackTag); } transaction.commit(); }
Example 9
Source File: MediaRouteChooserDialogManager.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override protected DialogFragment openDialogInternal(FragmentManager fm) { if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null; Fragment fragment = new Fragment(this); MediaRouteSelector selector = mediaSource().buildRouteSelector(); if (selector == null) return null; fragment.setRouteSelector(selector); fragment.show(fm, DIALOG_FRAGMENT_TAG); fm.executePendingTransactions(); return fragment; }
Example 10
Source File: MediaRouteControllerDialogManager.java From delion with Apache License 2.0 | 5 votes |
@Override protected DialogFragment openDialogInternal(FragmentManager fm) { if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null; MediaRouteControllerDialogFragment fragment = new MediaRouteControllerDialogFragment() { final SystemVisibilitySaver mVisibilitySaver = new SystemVisibilitySaver(); @Override public void onStart() { mVisibilitySaver.saveSystemVisibility(getActivity()); super.onStart(); } @Override public void onStop() { super.onStop(); mVisibilitySaver.restoreSystemVisibility(getActivity()); } @Override public void onDismiss(DialogInterface dialog) { delegate().onDialogCancelled(); androidMediaRouter().removeCallback(mCallback); mDialogFragment = null; super.onDismiss(dialog); } }; MediaRouteSelector selector = mediaSource().buildRouteSelector(); if (selector == null) return null; androidMediaRouter().addCallback(selector, mCallback); fragment.show(fm, DIALOG_FRAGMENT_TAG); fm.executePendingTransactions(); return fragment; }
Example 11
Source File: MediaRouteControllerDialogManager.java From 365browser with Apache License 2.0 | 5 votes |
@Override protected DialogFragment openDialogInternal(FragmentManager fm) { if (fm.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) return null; Fragment fragment = new Fragment(this, mCallback); MediaRouteSelector selector = mediaSource().buildRouteSelector(); if (selector == null) return null; androidMediaRouter().addCallback(selector, mCallback); fragment.show(fm, DIALOG_FRAGMENT_TAG); fm.executePendingTransactions(); return fragment; }
Example 12
Source File: FragmentTransitionDefaultFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
private void showNextFragment() { FragmentActivity activity = getActivity(); if (activity == null) { return; } FragmentManager fm = activity.getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.replace(R.id.fragment, new FragmentTransitionSecondFragment(), FragmentTransitionSecondFragment.FRAGMENT_TAG); ft.addToBackStack(null); ft.commit(); fm.executePendingTransactions(); }
Example 13
Source File: ErrorDialogManager.java From KUtils with Apache License 2.0 | 5 votes |
public static void attachTo(Activity activity, Object executionScope, boolean finishAfterDialog, Bundle argumentsForErrorDialog) { FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager(); SupportManagerFragment fragment = (SupportManagerFragment) fm.findFragmentByTag(TAG_ERROR_DIALOG_MANAGER); if (fragment == null) { fragment = new SupportManagerFragment(); fm.beginTransaction().add(fragment, TAG_ERROR_DIALOG_MANAGER).commit(); fm.executePendingTransactions(); } fragment.finishAfterDialog = finishAfterDialog; fragment.argumentsForErrorDialog = argumentsForErrorDialog; fragment.executionScope = executionScope; }
Example 14
Source File: RxLocationSettings.java From android-rxlocationsettings with Apache License 2.0 | 5 votes |
@NonNull static ResolutionFragment from(@NonNull FragmentManager fragmentManager) { ResolutionFragment resolutionFragment = (ResolutionFragment) fragmentManager.findFragmentByTag(TAG); if (resolutionFragment == null) { resolutionFragment = new ResolutionFragment(); fragmentManager .beginTransaction() .add(resolutionFragment, TAG) .commit(); fragmentManager.executePendingTransactions(); } return resolutionFragment; }
Example 15
Source File: Wizard.java From Wizard with Apache License 2.0 | 5 votes |
public void init() { if (!activity.isFinishing()) { FragmentManager fragmentManager = activity.getSupportFragmentManager(); fragmentManager.addOnBackStackChangedListener(this); WizardPage firstPage = pages[0]; fragmentManager.beginTransaction().replace(containerId, firstPage.createFragment()).commit(); fragmentManager.executePendingTransactions(); if (firstPage.hasOptionMenu()) { activity.supportInvalidateOptionsMenu(); } firstPage.setupActionBar(actionBarResolver.getSupportActionBar()); } }
Example 16
Source File: ActivityLauncher.java From ActivityLauncher with Apache License 2.0 | 5 votes |
private RouterFragmentV4 getRouterFragmentV4(FragmentActivity activity) { RouterFragmentV4 routerFragment = findRouterFragmentV4(activity); if (routerFragment == null) { routerFragment = RouterFragmentV4.newInstance(); FragmentManager fragmentManager = activity.getSupportFragmentManager(); fragmentManager .beginTransaction() .add(routerFragment, TAG) .commitAllowingStateLoss(); fragmentManager.executePendingTransactions(); } return routerFragment; }
Example 17
Source File: BaseFragmentAdapter.java From youqu_master with Apache License 2.0 | 5 votes |
public void setFragments(FragmentManager fm,List<Fragment> fragments,List<String> mTitles) { this.mTitles = mTitles; if (this.fragmentList != null) { FragmentTransaction ft = fm.beginTransaction(); for (Fragment f : this.fragmentList) { ft.remove(f); } ft.commitAllowingStateLoss(); ft = null; fm.executePendingTransactions(); } this.fragmentList = fragments; notifyDataSetChanged(); }
Example 18
Source File: MainActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //getSupportFragmentManager().beginTransaction().add(R.id.frag_container, firstFragment).commit(); //first find the 3 fragments, if create them as needed. //Remember fragments can survive the restart of an activity on orientation change. FragmentManager fragmentManager = getSupportFragmentManager(); if (savedInstanceState != null) { leftfrag = (FragLeft) fragmentManager.getFragment(savedInstanceState, "LEFT"); midfrag = (FragMid) fragmentManager.getFragment(savedInstanceState,"MIDDLE"); rightfrag = (FragRight) fragmentManager.getFragment(savedInstanceState,"RIGHT"); //since survived, remove them from the fragment manager, so don't double add them. FragmentTransaction remove = fragmentManager.beginTransaction(); remove.remove(leftfrag); remove.remove(midfrag); remove.remove(rightfrag); if (!remove.isEmpty()) { remove.commit(); fragmentManager.executePendingTransactions(); } } else { leftfrag = new FragLeft(); midfrag = new FragMid(); rightfrag = new FragRight(); } viewPager = (ViewPager) findViewById(R.id.pager); if (viewPager != null) { //in portrait mode viewPager.setAdapter(new ThreeFragmentPagerAdapter(fragmentManager)); } else { //in landscape mode fragmentManager.beginTransaction() .add(R.id.frag_left, leftfrag, "LEFT") .add(R.id.frag_mid, midfrag, "MIDDLE") .add(R.id.frag_right, rightfrag, "RIGHT") .commit(); } }
Example 19
Source File: MainActivity.java From OneTapVideoDownload with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { if (BuildConfig.DEBUG) { StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .penaltyLog() .build() ); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentByTag(ViewPagerFragmentParent.FRAGMENT_TAG) == null) { FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.content_frame, new ViewPagerFragmentParent(), ViewPagerFragmentParent.FRAGMENT_TAG); ft.commit(); fm.executePendingTransactions(); } FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.getInstance(this); Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Activity~" + getClass().getName()); firebaseAnalytics.logEvent(FirebaseAnalytics.Event.APP_OPEN, bundle); if (CheckPreferences.xposedErrorsEnabled(this)) { checkXposedInstallation(); } mApplicationUpdateNotification = new ApplicationUpdateNotification(this); mApplicationUpdateNotification.checkForUpdate(); onNewIntent(getIntent()); if (Global.isPlaystoreAvailable(this)) { FirebaseMessaging.getInstance().subscribeToTopic("playstore_users_notifications");; } else { FirebaseMessaging.getInstance().subscribeToTopic("non_playstore_users_notifications"); } ThemeManager.applyTheme(this); }
Example 20
Source File: MainActivity.java From ui with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fragmentManager = getSupportFragmentManager(); if (savedInstanceState != null) { one = (PageFragment) fragmentManager.getFragment(savedInstanceState, "ONE"); two = (PageFragment) fragmentManager.getFragment(savedInstanceState, "TWO"); three = (PageFragment) fragmentManager.getFragment(savedInstanceState, "THREE"); four = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FOUR"); five = (PageFragment) fragmentManager.getFragment(savedInstanceState, "FIVE"); //since survived, need to clean up or I can't add them to the pagers adapter again. FragmentTransaction remove = fragmentManager.beginTransaction(); remove.remove(one); remove.remove(two); remove.remove(three); remove.remove(four); remove.remove(five); if (!remove.isEmpty()) { remove.commit(); fragmentManager.executePendingTransactions(); } } else { one = PageFragment.create(1); two = PageFragment.create(2); three = PageFragment.create(3); four = PageFragment.create(4); five = PageFragment.create(5); } viewPager = (ViewPager) findViewById(R.id.pager); if (viewPager != null) { //in portrait mode viewPager.setAdapter(new ThreeFragmentPagerAdapter(5)); } else { //in landscape mode viewPager1 = (ViewPager) findViewById(R.id.pagerleft); viewPager1.setAdapter(new ThreeFragmentPagerAdapter(2)); viewPager2 = (ViewPager) findViewById(R.id.pagerright); viewPager2.setAdapter(new ThreeFragmentPagerAdapter(3)); } }