We have found several cases for this kind of crashes reported by backend logging monitoring. It seems the crashes do not tie to particular UX failure. And from the reports,
I had this same issue. I setup an animation
and in onAnimationEnd
I was removing the object that had been animated which is when problems started. What I did was setup an asynchronous Runnable
to wait 100 milliseconds after the animation had stopped before removing the animated object:
the object previously animated is this._loader
private void removeLoader() {
final ContentContainer self = this; // "CustomContainer" needs to match the type of `this`
Handler h = new Handler();
h.postAtTime(new Runnable() {
@Override
public void run() {
MainActivity.instance.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if(self._loader == null) {
// there is no loader. quit now while you still have the chance!!
return;
}
while(self._loader.getParent() != null) {
removeView(self._loader);
}
} catch(Exception e) {
Crashlytics.logException(e);
e.printStackTrace();
}
self._loader = null;
}
});
}
}, 100);
}
Cheers
We started getting this error unexpectedly too. It was tracked down to fragment animations being the issue. More specifically using custom animations with replace()
in a fragment transaction when the app is built against Local Maven repository for Support Libraries
rev > 26.
Downgrade Local Maven repository for Support Libraries
to rev 26. See here
Override dispatchDraw method and put in it a try/catch block, like this:
public void dispatchDraw(Canvas c)
{
try
{
super.dispatchDraw(c);
return;
}
catch(Exception exception)
{
return;
}
}
It's a threading issue. Could be that you're refreshing your ViewPager
or some other adapter.
Have been facing this issue on and off, and realised that if you place it in the UI Thread in your Activity
, then it'll render just fine.
activity?.runOnUiThread{
// Add Your UI Updating Methods Here
}
I was trying to navigate from Fragment A to Fragment B, and Fragment A was a form that required data from Fragment B.
So when I tried to navigate without filling up A, it was throwing this exception.
Also, even if A was independent of the data B, it was throwing this exception.
I have no idea why but I added a condition where the user had to fill-up the form before navigating away and that solved the issue.
Possible cause: I was having the exact same issue. It turned out it started to happen when I added code to modify the view tree within onDraw() call. To be specific, I removed a view with children in my derived onDraw() when certain conditions were met. I now believe this is a bad thing to do, probably because the platform is trying to draw views that I have now removed from the view tree. I resolved the issue by posting the deletion with Runnable to happen after the call to onDraw() has finished.