I turned off all animations on developer options. But I still get this exception when trying to click on one of the buttons.
My app is indeed active and not idle ent
you can check this wayes:
way 1: disable animation in developer options:
Setting -> developer options -> Window animation scale -> off
Transition animation scale -> off
Animator duration scale -> off
way 2: if you have customView in build.gradle use this
defaultConfig {
//...
testOptions {
animationsDisabled = true
}
}
As per answer by MaciejGórski to the similar question:
It was a bug in my app code, where
SwipeRefreshLayout
animated itself indefinitely. Due to a bug in this component, the refresh state was not even showing.
I have been struggling with this problem for the last few days.
Here is a method that I used to identify "violators":
private void dumpThreads() {
int activeCount = Thread.activeCount();
Thread[] threads = new Thread[activeCount];
Thread.enumerate(threads);
for (Thread thread : threads) {
System.err.println(thread.getName() + ": " + thread.getState());
for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
System.err.println("\t" + stackTraceElement);
}
}
}
In my case, Facebook SDK was using the AsyncTask thread pool.
In my case this problem was happening with AnimatedVectorDrawable
and caused by an objectAnimator
that was set to repeat the animation infinitely (android:repeatCount="infinite"
). .
The problem was also present only on older platform versions. Tests were perfectly working on Android 9 while the problem was reproducible on Android 5 and 6 (not sure about 7 and 8 at the moment).
I believe, the root cause of the problem is the same as for indeterminate progress bars (covered in this SO question). However, I haven't found any nice solution, only workarounds.
One of the workarounds is to detect that the animation is turned off (animator duration is 0) in the setting and don't start the animation. Of course, this only works for platform versions where the animation does not autostart.
private fun startIconAnimation(imageView: ImageView) {
if (areAnimationsEnabled()) {
(imageView.drawable as Animatable).start()
}
}
private fun areAnimationsEnabled(): Boolean {
val animatorDurationScale = Settings.Global.getFloat(
requireContext().contentResolver,
Settings.Global.ANIMATOR_DURATION_SCALE,
1.0f
)
return animatorDurationScale != 0.0f
}
Note: API level 26 introduced a static method ValueAnimator.areAnimatorsEnabled()
which would have been handy if the problem was not happening only on the older platform versions.