0

I wanted to animate a button, so I used this answer:

https://stackoverflow.com/a/4852468/559525

and got it animating on the first attempt. But then when I tried to stop the animation from various places in my application, I found that it will ONLY stop the animation if I call view.clearAnimation() from inside the onClick() callback.

My first guess is this has to do with multi threading synchronize issues, but I know about the UI thread and I was pretty sure I was calling the clearAnimation() method from approved places in the main UI thread.

My other thought was that the UI needed to be invalidated or refreshed? But I tried putting this call right before doing an invalidate on my main layout and that didn't help. I know my invalidate is working properly because it works to update other button attributes like color.

Thanks for any advice!

Community
  • 1
  • 1
Eradicatore
  • 1,501
  • 2
  • 20
  • 38
  • How did you access the animation from other places? Please try to print the hashCode() of that animation object when creating it, and when clearing the animation from all those places. If the hashCode()s are different - you're not accessing the right object – Udinic Jun 19 '12 at 23:27
  • Thanks for the tip. I did print out the hash code in both places and got the following output: ` 06-20 09:41:48.428: I/GDOOR(20318): wifi check btn hash:1094513400 06-20 09:41:59.952: I/GDOOR(20318): onclick main hash:1094513400 ` Note the second one did stop the animation, but the first one didn't. I'll try to isolate out the code that will help others verify/try what I'm seeing and post it here today. – Eradicatore Jun 20 '12 at 15:09
  • Ok, sorry. I found my bug. I should have started up the debugger and stepped through since that would have found it. I was calling startAnimation() after calling the asyncTask method. So it was happening so quickly that I was calling clearAnimation BEFORE the animation was ever started! Sorry for the false alarm! – Eradicatore Jun 20 '12 at 22:20
  • no worries, everyone makes mistakes :) – Udinic Jun 20 '12 at 22:48

0 Answers0