8

Here is the link to recording while pressing back button

While i am using a animation in a fragment transaction it's working fine but i am getting a flicker of the next screen which is annoying me. I have been searching for it since 2 days no progress.

I am using this code for transition

public void moveToBaseSelect() {
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.setCustomAnimations(R.anim.enter_from_right,R.anim.exit_to_left,R.anim.enter_from_left,R.anim.exit_to_right);
    ft.replace(R.id.home_frame, new BaseSelectFragment(), HomeActivity.BASE_SELECT);
    ft.addToBackStack(HomeActivity.BASE_SELECT);
    ft.commit();

}

public void moveToLogin()
{
    if(fragmentManager.getBackStackEntryCount()>=1 && fragmentManager.getBackStackEntryAt(fragmentManager.getBackStackEntryCount()-1).getName().equals(HomeActivity.LOGIN))
        return;

    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.setCustomAnimations(R.anim.enter_from_right,R.anim.exit_to_left,R.anim.enter_from_left,R.anim.exit_to_right);
    ft.replace(R.id.home_frame, new LoginFragment(), HomeActivity.LOGIN);
    ft.addToBackStack(HomeActivity.LOGIN);
    ft.commit();
}

The anim files

enter from left

<set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fillAfter="true"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXDelta="-100%p"
        android:toXDelta="0%p" />
</set>
</set>

Enter from right

<?xml version="1.0" encoding="utf-8"?>
<set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fillAfter="true"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXDelta="100%p"
        android:toXDelta="0%p" />
</set>
</set>

exit to left

<?xml version="1.0" encoding="utf-8"?>
<set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fillAfter="true"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXDelta="0%p"
        android:toXDelta="-100%p" />
</set>
</set>

exit to right

 <?xml version="1.0" encoding="utf-8"?>
<set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fillAfter="true"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXDelta="0%p"
        android:toXDelta="100%p" />
</set>
</set>

I have tried a alternative that's working by using animator instead of anim and app.fragment instead of v4.fragment

But I am extremely curious to know is there any solution if i stick with the anim method

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Milind Chaudhary
  • 1,632
  • 1
  • 17
  • 16

2 Answers2

9

Remove your <set> elements in your animation files. I just had this problem and It disappeared when I removed them.

My xml for an animation:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_mediumAnimTime"
    android:fromXDelta="0%"
    android:toXDelta="-100%" />

A.Danibo
  • 494
  • 1
  • 4
  • 16
2

The issue is because commit() is asynchronous and presumably some race condition causes the flickering. Solved by making transaction manager do commitNow() instead of commit()

pete
  • 1,878
  • 2
  • 23
  • 43