views:

250

answers:

1

I ran into an interesting situation with using a ProgressBar in an App Widget... The documentation (http://developer.android.com/guide/topics/appwidgets/index.html) says that ProgressBar is a supported widget class...

I have no problem getting the ProgressBar to display in my App Widget but the problem is that I want it to only be displayed as visual feedback to the user when background processing is happening.

On ImageViews I do this via RemoteViews.setViewVisibility() and everything works fine. However, with ProgressBar I get an exception saying that ProgressBar can't use this method.

Is this intentional or is this a bug? Is there any way to workaround this problem?

+2  A: 

It might be a bug. There's a particular annotation (@RemotableViewMethod) you need in the Java source code of Android itself to mark a method as being available via RemoteViews. View has this for setVisibility(), but ProgressBar overrides that method and does not have the annotation on its own edition. If @RemotableViewMethod is not inherited, and the override "undoes" the annotation, that would explain the symptom you see.

A workaround is to use two app widget layouts and choose the one you want (with or without ProgressBar) when you create your RemoteViews object when updating your app widget.

I'll make a note to try to replicate this and, if I see the same thing, I'll post an issue on it on the Android issue tracker.

CommonsWare
Thanks for the info and the workaround! Just as an FYI, I am currently compiling against the 1.5 SDK so it may have been fixed in a later version.
Justin
Probably not, since I was looking at more current code (via Google Code Search) when writing the answer.
CommonsWare