I\'m inserting Fragments into the Activity using this code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setCon
As a workaround for this you can use onCreateAnimator/onCreateAnimation methods in your fragments.
For example for native fragments implementation:
@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
if (enter) {
return AnimatorInflater.loadAnimator(getActivity(), R.animator.slide_in_top);
} else {
return AnimatorInflater.loadAnimator(getActivity(), R.animator.fade_out);
}
}
The same technique for support library fragments with Animation instead. In this case you also have more control over how would you like to play animation depending upon fragment state and/or arguments.
An alternative suggestion to work around this issue is to download the source for the support library and make the change I suggested in the defect (http://code.google.com/p/android/issues/detail?id=25994) yourself, of course this means maintaining a copy of the support library yourself and not being able to use the native support, however that depends on how important this issue is for you.
Okay so this is a bug which also is a problem for native library (not only support library).
The only workaround I can suggest is to create your own back stack and then handle onBack with your own custom implementation setting the right animation as you go back through your own stack.
You can use onCreateAnimation plus AnimationUtils for each fragment instead of transaction.setCustomAnimations(..). Also to skip animation during restoring, consider about boleean flag.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
mIsRestoring = savedInstanceState != null;
...
}
@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
if (mIsRestoring) {
mIsRestoring = false;
return null;
}
if (enter) {
return AnimationUtils.loadAnimation(getContext(), R.anim.enter_from_right);
} else {
return AnimationUtils.loadAnimation(getContext(), R.anim.exit_to_left);
}
}
This bug is fixed few days ago in new support library 23.3.0
.
https://code.google.com/p/android/issues/detail?id=25994#c36