Java Code Examples for android.support.v4.app.FragmentTransaction#addToBackStack()
The following examples show how to use
android.support.v4.app.FragmentTransaction#addToBackStack() .
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: DialogHelper.java From HeartbeatFixerForGCM with Apache License 2.0 | 6 votes |
private static void showDialog(@NonNull AppCompatActivity activity, @NonNull DialogFragment fragment, @NonNull String tag) { if (Looper.myLooper() != Looper.getMainLooper()) { throw new RuntimeException("Should be called on the main thread"); } FragmentManager fm = activity.getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag(tag); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); fragment.show(ft, tag); }
Example 2
Source File: GroupListFragment.java From glimmr with Apache License 2.0 | 6 votes |
@Override public void onLongClickDialogSelection(Group group, int which) { Log.d(TAG, "onLongClickDialogSelection()"); FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); if (group != null) { Fragment prev = mActivity.getSupportFragmentManager() .findFragmentByTag(AddToGroupDialogFragment.TAG); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); DialogFragment newFragment = AddToGroupDialogFragment.newInstance(group); newFragment.show(ft, AddToGroupDialogFragment.TAG); } else { Log.e(TAG, "onLongClickDialogSelection: group is null"); } }
Example 3
Source File: MusicPlayerActivity.java From LyricHere with Apache License 2.0 | 6 votes |
private void navigateToBrowser(String mediaId) { LogUtils.d(TAG, "navigateToBrowser, mediaId=" + mediaId); MediaBrowserFragment fragment = getBrowseFragment(); if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) { fragment = new MediaBrowserFragment(); fragment.setMediaId(mediaId); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // TODO support animations //transaction.setCustomAnimations( // R.animator.slide_in_from_right, R.animator.slide_out_to_left, // R.animator.slide_in_from_left, R.animator.slide_out_to_right); transaction.replace(R.id.container, fragment, FRAGMENT_TAG); // If this is not the top level media (root), we add it to the fragment back stack, // so that actionbar toggle and Back will work appropriately: if (mediaId != null) { transaction.addToBackStack(null); } transaction.commit(); } }
Example 4
Source File: MultiPaneActivity.java From MongoExplorer with MIT License | 6 votes |
@Override protected void loadDocumentListPane(long connectionId, int collectionIndex) { DocumentListFragment fragment = DocumentListFragment.newInstance(connectionId, collectionIndex, true); FragmentManager fm = getSupportFragmentManager(); boolean alreadyShiftedFrames = fm.getBackStackEntryCount() > 0; if (!alreadyShiftedFrames) shiftAllLeft(mFrame1, mFrame2, mFrame3); Fragment connectionList = fm.findFragmentById(R.id.frame_1); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.frame_3, fragment); if (!alreadyShiftedFrames) { ft.remove(connectionList); ft.addToBackStack("doclist"); } ft.commit(); }
Example 5
Source File: MvcDialog.java From AndroidMvc with Apache License 2.0 | 5 votes |
/** * Show dialog. * @param fragmentManager The fragment manager. Usually it's the child fragment manager of the * fragment on which the dialog will show * @param dialogClass The class type of the dialog extending {@link MvcDialog} */ public static void show(FragmentManager fragmentManager, Class<? extends MvcDialog> dialogClass) { FragmentTransaction ft = fragmentManager.beginTransaction(); MvcDialog dialogFragment = (MvcDialog) fragmentManager.findFragmentByTag(dialogClass.getName()); if (dialogFragment == null) { try { dialogFragment = new ReflectUtils.newObjectByType<>(dialogClass).newInstance(); } catch (Exception e) { e.printStackTrace(); } } ft.addToBackStack(null); dialogFragment.show(ft, dialogClass.getName()); }
Example 6
Source File: ShiftLauncherView.java From shift with Apache License 2.0 | 5 votes |
private void addFragment(FragmentActivity activity, Fragment fragment, String tag, boolean isVisible) { FragmentManager manager = activity.getSupportFragmentManager(); Fragment oldInstance = manager.findFragmentByTag(tag); if (oldInstance == null) { FragmentTransaction transaction = manager.beginTransaction(); transaction.add(android.R.id.content, fragment, tag); if (!isVisible) { transaction.hide(fragment); } else if (tag.equals(TABS_TAG)) { manager.popBackStack(TABS_BACK_STACK, FragmentManager.POP_BACK_STACK_INCLUSIVE); transaction.addToBackStack(TABS_BACK_STACK); } transaction.commit(); } }
Example 7
Source File: FragmentHelper.java From OmniList with GNU Affero General Public License v3.0 | 5 votes |
private static void replace(AppCompatActivity activity, Fragment fragment, @IdRes int containerId, boolean backStack) { if (activity.isFinishing()) return; FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); setCustomAnimations(transaction); if (backStack) transaction.addToBackStack(null); transaction.replace(containerId, fragment).commit(); }
Example 8
Source File: ChooseContactActivity.java From Conversations with GNU General Public License v3.0 | 5 votes |
protected void showEnterJidDialog(XmppUri uri) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); Jid jid = uri == null ? null : uri.getJid(); EnterJidDialog dialog = EnterJidDialog.newInstance( mActivatedAccounts, getString(R.string.enter_contact), getString(R.string.select), jid == null ? null : jid.asBareJid().toString(), getIntent().getStringExtra(EXTRA_ACCOUNT), true, false ); dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> { final Intent request = getIntent(); final Intent data = new Intent(); data.putExtra("contact", contactJid.toString()); data.putExtra(EXTRA_ACCOUNT, accountJid.toEscapedString()); data.putExtra(EXTRA_SELECT_MULTIPLE, false); copy(request, data); setResult(RESULT_OK, data); finish(); return true; }); dialog.show(ft, "dialog"); }
Example 9
Source File: CharacterListFragment.java From Qachee with Apache License 2.0 | 5 votes |
public void replace(FragmentActivity activity, Fragment newFragment) { FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(R.id.container, newFragment).commit(); }
Example 10
Source File: MainActivity.java From notSABS with MIT License | 5 votes |
public void donateSettings(View view) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit); fragmentTransaction.replace(R.id.fragmentContainer, new DonateFragment()); fragmentTransaction.addToBackStack("donate_settings"); fragmentTransaction.commit(); }
Example 11
Source File: OpmlActivity.java From SimpleNews with Apache License 2.0 | 5 votes |
@Override public void assignFeeds(List<Feed> feeds) { FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_right, R.anim.slide_out_right); t.replace(R.id.container, OpmlAssignFragment.newInstance(feeds), OPML_ASSIGN_TAG); t.addToBackStack(null); t.commit(); supportInvalidateOptionsMenu(); }
Example 12
Source File: RMBTMainActivity.java From open-rmbt with Apache License 2.0 | 5 votes |
public void showAbout() { popBackStackFull(); FragmentTransaction ft; ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, new RMBTAboutFragment(), AppConstants.PAGE_TITLE_ABOUT); ft.addToBackStack(AppConstants.PAGE_TITLE_ABOUT); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); refreshActionBar(AppConstants.PAGE_TITLE_ABOUT); }
Example 13
Source File: FragmentUtility.java From nano-wallet-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * Performs a fragment replacement transaction with all of the necessary animations and tags. */ public void performReplaceTransaction(Fragment fragment, Animation pushAnimations, Animation popAnimations, @Nullable String tag, boolean addToBackStack) { FragmentTransaction transaction; if (tag == null) { transaction = mFragmentManager.beginTransaction() .setCustomAnimations( pushAnimations.getEnter(), popAnimations.getExit(), popAnimations.getEnter(), pushAnimations.getExit() ) .replace(mContainerViewId, fragment); } else { transaction = mFragmentManager.beginTransaction() .setCustomAnimations( pushAnimations.getEnter(), popAnimations.getExit(), popAnimations.getEnter(), pushAnimations.getExit() ) .replace(mContainerViewId, fragment, tag); } if (addToBackStack) { transaction.addToBackStack(tag); } transaction.commitAllowingStateLoss(); }
Example 14
Source File: BreadcrumbFragment.java From BreadcrumbToolbar with Apache License 2.0 | 5 votes |
public static void open(FragmentActivity activity, boolean addToBackStack, String name) { Fragment fragment = new BreadcrumbFragment(); FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction(); ft.replace(R.id.main_content, fragment); if (addToBackStack) { ft.addToBackStack(null); } if (name != null) { Bundle bundle = new Bundle(); bundle.putString(FRAGMENT_NAME_TAG, name); fragment.setArguments(bundle); } ft.commit(); }
Example 15
Source File: MainActivity.java From fuckView with GNU Affero General Public License v3.0 | 5 votes |
private void setFragment(Fragment fragment, boolean backable) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.fl, fragment); if (backable) { transaction.addToBackStack(null); } transaction.commitAllowingStateLoss(); currentFragment = fragment; shouldShowFAQ = fragment instanceof Searchable; invalidateOptionsMenu(); }
Example 16
Source File: MediaSourcePickDialogFragment.java From q-municate-android with Apache License 2.0 | 5 votes |
@Override public void show(FragmentManager fragmentManager, String tag) { fragmentManager.popBackStack(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); //add fragment to backstack for getting permission request result to this fragment fragmentTransaction.addToBackStack(null); fragmentTransaction.add(this, tag); fragmentTransaction.commit(); }
Example 17
Source File: Flowr.java From flowr with Apache License 2.0 | 4 votes |
/** * * @param data TransactionData used to configure fragment transaction * @param <T> type Fragment & FlowrFragment * @return id Identifier of the committed transaction. */ protected <T extends Fragment & FlowrFragment> int displayFragment(TransactionData<T> data) { int identifier = -1; try { if (screen == null) { return identifier; } injectDeepLinkInfo(data); if (data.isClearBackStack()) { clearBackStack(); } currentFragment = retrieveCurrentFragment(); Fragment fragment = data.getFragmentClass().newInstance(); fragment.setArguments(data.getArgs()); FragmentTransaction transaction = screen.getScreenFragmentManager().beginTransaction(); if (!data.isSkipBackStack()) { String id = tagPrefix + screen.getScreenFragmentManager().getBackStackEntryCount(); transaction.addToBackStack(id); } setCustomAnimations(transaction, data.getEnterAnim(), data.getExitAnim(), data.getPopEnterAnim(), data.getPopExitAnim()); if (data.isReplaceCurrentFragment()) { transaction.replace(mainContainerId, fragment); } else { transaction.add(mainContainerId, fragment); } identifier = transaction.commit(); if (data.isSkipBackStack()) { setCurrentFragment(fragment); } } catch (Exception e) { Log.e(TAG, "Error while displaying fragment.", e); } return identifier; }
Example 18
Source File: RMBTMainActivity.java From open-rmbt with Apache License 2.0 | 4 votes |
/** * @param testPoint * @param mapType * */ public RMBTMapFragment showMap(String mapType, LatLng initialCenter, boolean clearFilter, int viewId, boolean popBackStack) { if (popBackStack) { popBackStackFull(); } FragmentTransaction ft; setCurrentMapType(mapType); if (clearFilter) { final List<MapListSection> mapFilterListSelectionList = getMapFilterListSelectionList(); if (mapFilterListSelectionList != null) { for (final MapListSection section : mapFilterListSelectionList) { for (final MapListEntry entry : section.getMapListEntryList()) entry.setChecked(entry.isDefault()); } updateMapFilter(null); } } final RMBTMapFragment fragment = new RMBTMapFragment(); final Bundle bundle = new Bundle(); bundle.putParcelable("initialCenter", initialCenter); if (viewId >= 0) { bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_ALL_GESTURES, false); bundle.putBoolean(RMBTMapFragment.OPTION_SHOW_INFO_TOAST, false); bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_CONTROL_BUTTONS, false); bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_OVERLAY, false); fragment.setArguments(bundle); ft = fm.beginTransaction(); //replace the given viewgroup, but do not add to backstack ft.replace(viewId, fragment, AppConstants.PAGE_TITLE_MINI_MAP); //ft.addToBackStack(AppConstants.PAGE_TITLE_MINI_MAP); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); } else { System.out.println("SHOW MAP"); fragment.setArguments(bundle); ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_MAP); ft.addToBackStack(AppConstants.PAGE_TITLE_MAP); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); refreshActionBar(AppConstants.PAGE_TITLE_MAP); } return fragment; }
Example 19
Source File: FragmentUtils.java From TikTok with Apache License 2.0 | 4 votes |
/** * 操作fragment * * @param fragmentManager fragment管理器 * @param srcFragment 源fragment * @param destFragment 目标fragment * @param type 操作类型 * @param sharedElements 共享元素 * @return destFragment */ private static Fragment operateFragment(@NonNull FragmentManager fragmentManager, Fragment srcFragment, @NonNull Fragment destFragment, int type, SharedElement... sharedElements) { if (srcFragment == destFragment) return null; if (srcFragment != null && srcFragment.isRemoving()) { // Log.e(srcFragment.getClass().getSimpleName() + " is isRemoving"); return null; } String name = destFragment.getClass().getSimpleName(); Bundle args = destFragment.getArguments(); FragmentTransaction ft = fragmentManager.beginTransaction(); if (sharedElements == null || sharedElements.length == 0) { ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); } else { for (SharedElement element : sharedElements) {// 添加共享元素动画 ft.addSharedElement(element.sharedElement, element.name); } } switch (type) { case TYPE_ADD_FRAGMENT: if (srcFragment != null) ft.hide(srcFragment); if (destFragment.isAdded()) break; ft.add(args.getInt(ARGS_ID), destFragment, name); if (args.getBoolean(ARGS_IS_HIDE)) ft.hide(destFragment); if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name); break; case TYPE_REMOVE_FRAGMENT: ft.remove(destFragment); break; case TYPE_REMOVE_TO_FRAGMENT: List<Fragment> fragments = getFragments(fragmentManager); for (int i = fragments.size() - 1; i >= 0; --i) { Fragment fragment = fragments.get(i); if (fragment == destFragment) { if (srcFragment != null) ft.remove(fragment); break; } ft.remove(fragment); } break; case TYPE_REPLACE_FRAGMENT: ft.replace(args.getInt(ARGS_ID), destFragment, name); if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name); break; case TYPE_POP_ADD_FRAGMENT: popFragment(fragmentManager); ft.add(args.getInt(ARGS_ID), destFragment, name); if (args.getBoolean(ARGS_IS_ADD_STACK)) ft.addToBackStack(name); break; case TYPE_HIDE_FRAGMENT: ft.hide(destFragment); break; case TYPE_SHOW_FRAGMENT: ft.show(destFragment); break; case TYPE_HIDE_SHOW_FRAGMENT: ft.hide(srcFragment).show(destFragment); break; } ft.commitAllowingStateLoss(); return destFragment; }
Example 20
Source File: ContainerFragment.java From pixate-freestyle-android with Apache License 2.0 | 3 votes |
/** * Replace an existing fragment that was added to a container. This is * essentially the same as calling * {@link FragmentTransaction#remove(Fragment)} for all currently added * fragments that were added with the same containerViewId and then * {@link FragmentTransaction#add(int, Fragment, String)} with the same * arguments given here. * * @param fragment The fragment to be added * @param addToBackStack {@code true} if this transaction should be added to * back stack */ public void replaceFragment(Fragment fragment, boolean addToBackStack) { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); if (addToBackStack) { ft.addToBackStack(null); } ft.replace(R.id.framelayout_container, fragment); ft.commit(); getChildFragmentManager().executePendingTransactions(); }