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!