You can have animations in App widgets.

There are several ways to do it depending on what kind of animation is
needed.

For Ryan's particular example, using the Alarm Manager with a
recurring alarm every second that calls OnUpdate() or some other
routine which updates the view would do the job.

Then in the updating routine, you just change the bitmap on an
ImageView which is part of your appwidgets layout.

You can certainly load a bitmap from resources or an external file and
update your imageview with that, but the bit I am not sure about is
whether you could create a bitmap on the fly and draw to it instead of
a Canvas, then load that into your imageview.

Assuming that works, the usual caveats of AppWidgets apply: if you
have an recurring alarm, it will be updating your widget in the
background whenever your phone is awake, e.g. even when your widget is
not visible.

This will cause extra strain on your battery and processor, depending
on how often you update and how much processing is required to do the
update. However, note that as long as you use the appropriate alarm
type: AlarmManager.RTC, then your updates will not be sent when the
phone is off, only when it is awake.

For what it is worth I had a similar situation where I updated every
minute, and there was no discernible battery drain, but every second
may be a different matter.

So depending on your needs, it may be worth implementing a toggle to
switch the animation on or off, to give the user the choice.



On Jun 22, 4:48 am, Mark Murphy <[email protected]> wrote:
> On Sun, Jun 20, 2010 at 2:14 PM, Ryan Detwiler <[email protected]> wrote:
> > I would like to make a simple 2x2 widget that displays a canvas that's
> > updated every second - how can I go about doing this?
>
> Write your own home screen application. You cannot have a Canvas in an
> app widget, and you cannot animate an app widget. Sorry!
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android App Developer Books:http://commonsware.com/books

-- 
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