I spent a lot of time looking for an android hello world widget how to but I couldn’t find a simple example so I had to spend some time on cutting an existing one into pieces and then start from scratch with a HelloWidget tutorial.

I hope this will help you to get started on android desktop widgets. Please give me some feedback about the tutorial and/or any errors or wrong explanations.

Download the tutorial here. Get the source code here.

11 Responses to “Android: HelloWidget Tutorial”

[...] to Android: HelloWidget Tutorial to get the updated turorial and sourcecode. I consider writing a small eBook. I will probably add [...]

mad.dogg

Juli 28th, 2009 - 21:01

Big thanks for the tutorial. I’ll look forward for the eBok :)

Latrell

August 5th, 2009 - 02:45

Many thanks!

Jeremy

August 7th, 2009 - 22:11

I ran into the same obstacle as you trying to piece together examples of widgets, then I found this link! Thanks!

For the time widget, why do you say the “service way” would eat more battery life (vs the “java way”)?

admin

August 9th, 2009 - 16:20

Hi Jeremy,

concerning the battery life, here’s what my tests tell me so far:
It seems, that the class derived from AppWidgetProvider is instantiated on every onUpdate call (which is called every ‘updatePerdiodMillis’) while my Task thread is hold in memory.
I tested that with some class variables. I created a private String test = “g” and did a test += “g” into the onUpdate method. My displayed String had the maximum of 2 times “g” (gg) while doing the same with a String test2 = “i” in my MyTime-class, I get a new “i” displayed to my widget every second my task is rerun.

I assume, that instantiating a new class every second compared to using an existing class in memory will eat up more battery. On the other hand, we might get the memory space problem when running a lot of widgets that store their stuff in memory which could be the point in this case
… is there any android core developer out there who can give us a statement about that?

ivy

August 13th, 2009 - 08:23

Hi.

Thanks for the tutorial. It helped me a lot. However, i still have questions when it comes to ui and listeners:

1. How can i add at least 3 button with different listeners for each.
2. I tried adding a seekbar and the “desktop widget” displayed “Problem loading widget”.

Hope you can help me with these. Many thanks. :)

Whirpig

Oktober 8th, 2009 - 02:18

Yes, it’s a good tutorial

tibo

November 30th, 2009 - 09:33

Thanks for this tutorial.

I want to update an ImageView on a desktop widget. How can i proceed. (I follow your tutorial and it works fine, but i’m unable to change my ImageView on upate)

Vikrant

Dezember 17th, 2009 - 18:29

Thanks a ton for beautiful tutorials….Well I agree with Jeremy comments about battery life and also it makes the phone unstable. The code instantiates a new class every 1 sec rather than using preloaded class and after 2-3 min the device shows up the signs of fatigue…Tut is good but design can be improved….anywys thnx for tut..

AC

Januar 8th, 2010 - 15:06

Thank you for this. Hugely appreciated. It’s like impossible to find a detailed tutorial on this.

Moppel

März 7th, 2010 - 23:32

Thanks to you! Very fine!

Leave a Reply

Let the other Follow you at twitter by clicking here.