In the thread here I mentioned how you can get simple tween and frame
animations working in AppWidgets.

http://groups.google.com/group/android-developers/browse_thread/thread/d1b17d287ea4be2a/243ba27b3db34b58?hl=en&lnk=gst&q=appwidget#243ba27b3db34b58

I realise the usual caveat with AppWidgets applies, they shouldn't be
updating that often due to battery issues, but I am using simple
animations that are triggered for a short period of time, not
animations that are playing permanently.

Having said that, those two methods work fine, but have limitations in
that both the tween and frame animations have to be prebuilt, and
stored in xml at compile time.

I am trying to be a bit more dynamic, and want to change the animation
at run time, e.g. by loading a different set of bitmaps for my frame
animation, based on say the user's choice from an SD card, such as a
few frames from an animated gif or short movie clip.

My current approach involves pre-loading the required frame bitmaps
into a series of invisible ImageViews in my RemoteViews object during
the initial OnUpdate. Then in response to a user's click, simulating
the animation in a Timer loop by showing and hiding the ImageViews via
the RemoteViews.setViewVisibility method.

It is fairly simple to show the next one in the list and hide the
previous one:
e.g.
        remoteViews.setViewVisibility(MyWidget.IMAGEVIEWS[timercount-1],
View.INVISIBLE);
        remoteViews.setViewVisibility(MyWidget.IMAGEVIEWS[timercount],
View.VISIBLE);
                appWidgetManager.updateAppWidget(thisWidget,
remoteViews);

This actually works pretty well on my device and the emulator, even
with a frame speed of 100milliseconds. However, after a while the
garbage collector gets triggered, and causes a noticeable pause in the
animation as the GC does its stuff.

I am being very careful not to allocate any new objects on my
animating timer loops, and I am also calling System.gc() before I
start my animation, so I suspect that it is the multiple calls to the
appWidgetManager's updateAppWidget() and what is happening inside that
which is causing the GC.

Is that likely to be internally allocating memory which is eventually
scheduled for clean up, or is it more likely my implementation is the
problem?  Note that I am using the same RemoteViews object for the
duration of the animation.

The only other way I can think of to do this would be to to set the
ImageView bitmaps dynamically within my timer loop, but that seems to
cause even more GC glitches on my initial investigations, than the
Show/Hide approach.

I do realise that this is not what AppWidgets were originally intended
for, but it seems to be a common request as they are currently limited
in terms of the views that are supported.

Regards
James

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to