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.
Posted in Android, Java |
[...] to Android: HelloWidget Tutorial to get the updated turorial and sourcecode. I consider writing a small eBook. I will probably add [...]
Big thanks for the tutorial. I’ll look forward for the eBok :)
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”)?
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?
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. :)
Yes, it’s a good tutorial
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)
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..
Thank you for this. Hugely appreciated. It’s like impossible to find a detailed tutorial on this.
Thanks to you! Very fine!
I love the tutorial, thanks a ton!
I am having one issue with it though. It seems that when I place the widget, it will work for a minute or so. Then after a minute or two of testing on my G1, the app dies and I get the following message “INFO/ActivityManager(30659): Process com.example.hellowidget (pid 4508) has died.”
Now I do believe that this is due to the phone running out of memory. But is there some way to prevent the app in the background from being killed or some other fix for this problem?
I have got the same problem, does anybody correct this one?
(environment 1.5 for me)
Do you guys have a lot of widgets running on your home screen? Remember that all home screen widgets run in the same process. Can you check the memory on the emulator with Eclipse? This might help to find out the problem. You can use your device for debugging over USB too.
Hello…
I’ve followed your tutorial, compiled it successfully but the widget is installed under launcher app, the widget doesn’t show on widget list (when i do long press on homescreen to choose widget). Need your help.
Thanx in advance
I was optimistic about this tutorial, but… it doesn’t work. I guess it’s too outdated or something. After all, it’s 1.5 based and we have 2.2 now.
A pity.
This tutorial will not work … doing it in 1.5.
I got the following error:
error: Error: No resource found that matches the given name (at ‘resource’ with value ‘@xml/hello_widget_provider’).
Thanks for the nice tutorial, good work!
The buttons extend some pixels above the background. But if you highlight the widget (as you do when you are about to drag it to the trash can) you notice that they are not; it is actually the background that has been drawn some pixels incorrectly hightwise so that the background is some pixels beneath (and outside) the lower border and some pixels beneath (and inside) the uppper borde, thus giving this strange appearance.
So, is it therefor the background that is wrong?
Perhaps not; why does the OS allow the widget to render itself outside of the reported boundaries?
Hi Thanks for the tutorial being new to android widgets i find this tutorial is very useful for me. I have a doubt i hope you can clear me. I need to set listener to that time widget which is displayed. Can you help me to set listener and bring the timepicker dialog to change the time manually in the widget.Can u help me for this.
Thanks, it was a very useful tut.
Nice tutorial, extactly what I was looking for……
Looking forward reading more tutorials.
Gute Arbeit, ich hoffe du machst weiter so :-)
Hello , I want to make Custome Home screen for Android Mob. I seen example in Android API Demo.
But I want to behave it like “App Widget Host”, so I can add Widget also.
Pls suggest me way to do.