0

I've been trying to add an AnimationDrawable in one of my app widgets. I create an xml resource file looking like this. It displays images of a led with the light on and off (so the animation is a blinking led).

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" >
    <item
        android:drawable="@drawable/time_circuits_led_on"
        android:duration="500"/>
    <item
        android:drawable="@drawable/time_circuits_led_off"
        android:duration="500"/>

</animation-list> 

When I installed my AppWidget on my phone, I saw no animation and after some research found that you can't animate drawable in an app widget.

I unlocked my phone a couple of minutes later, and the led was blinking, meaning the animation was working. Nowhere in my AppWidgetProvider do I call the AnimationDrawable#start() method, and so it should'nt be blinking, yet it is.

I locked and unlocked it again severall times, and sometimes the led blinks, sometimes it doesn't. If it blinks (sometimes) maybe there is something I can do to make sure it always blinks.

I'm running this on a Galaxy Nexus, running Android 4.1.1. I also tested this on a phone on Android 2.3.3 and the led never blinks.

XGouchet
  • 10,002
  • 10
  • 48
  • 83
  • I'm pretty sure that animation is *not* supported, as it would be a pretty serious battery hog. Perhaps whatever you are seeing on your Galaxy is some undefined behavior. If you really must have a blinking LED, perhaps you could have a background service broadcast a widget update message every 500ms? I don't necessarily think this is a great idea though. – Tim Oct 16 '12 at 21:48
  • I agree with you, from what i've read it shouldn't be blinking, yet it does, and regularly, so it must be the AnimationDrawable doing this. – XGouchet Oct 17 '12 at 12:57
  • 1
    I think the way to accomplish what you're trying to do is use a ViewFlipper, it is supported in RemoteViews. Though, in terms of battery use that doesn't look right. – Yulia Rogovaya Oct 19 '12 at 09:53
  • @YuliaRogovaya thanks for the tip, this really does work. As for the battery I will benchmark how much intense this is , I'll benchmark it. If you'd like to make this an answer, I'll accept it – XGouchet Oct 19 '12 at 13:22
  • You're welcome! I'll make this an answer – Yulia Rogovaya Oct 19 '12 at 17:10

1 Answers1

1

I think the way to accomplish what you're trying to do is use a ViewFlipper, it is supported in RemoteViews. Though, in terms of battery use that doesn't look right.

Yulia Rogovaya
  • 924
  • 1
  • 8
  • 26