1

I'm currently trying to implement fragment transaction animation like this (Fragment related classes are imported from support library):

FragmentTransaction trans = getFragmentManager().beginTransaction();
trans.setCustomAnimations(R.anim.slide_in,R.anim.slide_out);
trans.replace(R.id.preview_panel, fragment);
trans.commit();

The animations are defined like this:

slide_in.xml

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

slide_out.xml

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

Now whenever I run the transaction piece of code once it works fine. However when I run it a second time the app crashes with the following error:

Fatal signal 11 (SIGSEGV) at 0xff000008 (code=1), thread 11015

Whenever I remove the setCustomAnimations line this piece of code works fine every time it is run. What could be the issue here and how would I able able to solve/workaround it?

EDIT: Managed to narrow down the issue a little bit:

It happens when the fragment being replaced transaction contains a webview with the VideoEnabledWebChromeClient shown in this StackOverflow answer attached.

The error also only occurs on the fade out animation (that's why it seemed like it was only occuring the second time). When I change the animation to trans.setCustomAnimations(R.anim.eqdpost_slide_in,0); a it works fine.

Community
  • 1
  • 1
Leon Lucardie
  • 9,541
  • 4
  • 50
  • 70
  • I cannot tell you much with this piece of code, but this error happens often when you are trying to draw something outside the boundaries. – grzebyk Nov 27 '14 at 20:51

2 Answers2

2

I had a similar issue which I resolved by upgrading support-v4 library to 23.1.0 (from 23.0.1):

compile 'com.android.support:support-v4:23.1.0'

Travis
  • 1,926
  • 1
  • 19
  • 26
1

Figured out what was causing this issue.

It was this method in the fragment participating in the transaction, which is fired when the slide out animation occurs:

   @Override
    public void onDestroyView() {
        super.onDestroyView();
        _webView.destroy();
        _webView = null;
    }

The _webView.destroy() call releases the webview from memory. However, for some reason the _webView = null; statement doesn't just set the _webView pointer to null, it also calls the destroy() method on the webview on a native level before setting the _webView pointer to null. Because the webview has already been destroyed once the _webView = null; is called, it came up with the native error.

Changing the method as shown below fixes the issue:

    public void onDestroyView() {
        super.onDestroyView();
        _webView = null;
    }
Leon Lucardie
  • 9,541
  • 4
  • 50
  • 70