Skip to content

Instantly share code, notes, and snippets.

@pranaypatel512
Created April 28, 2016 06:42
Show Gist options
  • Save pranaypatel512/01dd58d98a91e16ab03950637752382d to your computer and use it in GitHub Desktop.
Save pranaypatel512/01dd58d98a91e16ab03950637752382d to your computer and use it in GitHub Desktop.
This method is used for fragment transaction
/**
* push fragment
*
* @param fragment fragment
* @param animate fragment transition animation
* @param shouldAdd add to back stack
* @param tag fragment tag
*/
public void pushFragments(Fragment fragment, boolean animate, boolean shouldAdd, String tag) {
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
if (animate) {
ft.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
}
if (shouldAdd) {
ft.replace(R.id.content, fragment, tag);
ft.addToBackStack(tag);
ft.commitAllowingStateLoss();
} else {
manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
ft.replace(R.id.content, fragment, tag);
ft.commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment