0

On navigating from one fragment to another which are part of same activity, I am using slide animation.

WebFragment fragment = WebFragment.newInstance(Globals.TGURL_CREATE_ACTIVITY, "");
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.enter_anim, R.anim.exit_anim);
transaction.replace(R.id.fragment_activity_layout, fragment);
transaction.addToBackStack(null);
transaction.commit();  

This code ensures that when I come back to the first fragment, animation is there.
Well this has been a boon for me so far. But in one specific case it is becoming a curse. The activity is placed on ActionBar tab. When the 2nd (WebFragment) is the current one, and I tap the tab and not the back button, I want the first fragment to be displayed without any animation.
But it has been impossible for me to do this so far as the navigation is inheriting the animation which was earlier given.
This is what I am doing for going back :

TabActivity.this.getSupportFragmentManager().popBackStack();
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
Nitish
  • 13,845
  • 28
  • 135
  • 263
  • This might provide you some hint. http://stackoverflow.com/questions/9194311/pop-the-fragment-backstack-without-playing-the-pop-animation – Satyen Udeshi Aug 21 '15 at 08:11
  • So from above link what you can do is use a static variable and when you don't want the animation then in the `onCreateAnimation` method use the static varialble and manage accordingly.. – Satyen Udeshi Aug 21 '15 at 08:15
  • @SatyenUdeshi : Already tried this. onCreateAnimation doesn't gets called on popBackStackImmediate. – Nitish Aug 21 '15 at 09:02

0 Answers0