Mastering Android Widget Development - Part1
In Days to Xmas tutorial you can see a simple widget example, which demonstrates what widgets are used for, and shows an example how they can work. Now I begin a series of tutorials to fully explain the working of widgets.
We will also create a sample application, during the tutorials, which will show a countdown to a given date in secunds, but things that are not required for this specific example applications will be explained too.
For this first part I will go though mainly the parts described in http://developer.android.com/g
Some general thoughts at first:
Most of the applications has a launcher activity, and the running begins with that, but its not necessary to have one. If you don't have one, the application wont show among the other installed programs giving the user the opportunity to run it.
If an application has a class that implements the AppwidgetProwider class, it will be showed among the available widgets.
Our application will be made up from the widget itself and a configuration activity where you can set the date to countdown to. In the architecture of widgets a "configuration" activity can be defined exactly for this, so we will not need the application to have a launcher activity, if there is a configuration defined it will automatically launched when a new widget is placed on the home screen.
When working with widgets you must keep in mind that the users can place multiple instances of the same widget to the home screen. The functionality of this case must be planned and coded. In the countdown widget id would be fine to the different instances to count to a different date. It will be our goal.
Lets see the basics of how widgets work:
Widgets use 4 intents
•ACTION_APPWIDGET_UPDATE
•ACTION_APPWIDGET_DELETED
•ACTION_APPWIDGET_ENABLED
•ACTION_APPWIDGET_DISABLED
You have to create an XML file with some metadata about the widget. For example countwidget_info.xml :
- <appwidget-provider xmlns:android="http://schemas.android.c
om/apk/res/android" - android:minWidth="294dp"
- android:minHeight="72dp"
- android:updatePeriodMillis="86400000"
- android:initialLayout="@layout/countdownwidget&
quot; - android:configure="com.helloandroid.countdo
wnexample.countdownConfigure&q uot; > - </appwidget-provider>
As you can see here we set:
•the widget size (you cant size it as you like, for details see App Widget Design Guidelines)
•the layout used
•the configuration activity mentioned before
•and the updateperiod
The update period is limited, for example in 1.5 it is said to refres every 30 min even if you set a shorter period.
If you set this an ACTION_APPWIDGET_UPDATE intent will be generated to perform the update.
If the device is asleep when it is time for an update then the device will wake up in order to perform the update.
Because the period can not be set as short as you like, and it wakes up the device we wont use it, we will generate the ACTION_APPWIDGET_UPDATE intents ourself using the AlarmManager class.
The widget must be registered in the AndroidMaifest.xml like this:
- <receiver android:name="CountdownWidget" >
- <intent-filter>
- <action android:name="android.appwidget.action
.APPWIDGET_UPDATE" /> - </intent-filter>
- <meta-data android:name="android.appwidget.provid
er" - android:resource="@xml/countwidget_info&qu
ot; /> - </receiver>
Here we set the CountWidget class to capture the APPWIDGET_UPDATE intent and attach the previously described metadata xml to it.
The system automatically cares about to the DELETE, ENABLE and DISABLE broadsets get captured too.
Now create the CountWidget class which implements the AppWidgetProvider.
At firs lest see the empty methods that we can owerride from the AppWidgetProvider.
In the comments I explain what they are used for.
- package com.helloandroid.countdownexam
ple; - import android.appwidget.AppWidgetMan
ager; - import android.appwidget.AppWidgetPro
vider; - import android.content.Context;
- import android.content.Intent;
- public class CountdownWidget extends AppWidgetProvider {
- @Override
- //called when widgets are deleted
- //see that you get an array of widgetIds which are deleted
- //so handle the delete of multiple widgets in an iteration
- super.onDeleted(context, appWidgetIds);
- }
- @Override
- super.onDisabled(context);
- //runs when all of the instances of the widget are deleted from
- //the home screen
- //here you can do some setup
- }
- @Override
- super.onEnabled(context);
- //runs when all of the first instance of the widget are placed
- //on the home screen
- }
- @Override
- //all the intents get handled by this method
- //mainly used to handle self created intents, which are not
- //handled by any other method
- //the super call delegates the action to the other methods
- //for example the APPWIDGET_UPDATE intent arrives here first
- //and the super call executes the onUpdate in this case
- //so it is even possible to handle the functionality of the
- //other methods here
- //or if you don't call super you can overwrite the standard
- //flow of intent handling
- super.onReceive(context, intent);
- }
- @Override
- int[] appWidgetIds) {
- //runs on APPWIDGET_UPDATE
- //here is the widget content set, and updated
- //it is called once when the widget created
- //and periodically as set in the metadata xml
- //the layout modifications can be done using the AppWidgetManager
- //passed in the parameter, we will discuss it later
- //the appWidgetIds contains the Ids of all the widget instances
- //so here you want likely update all of them in an iteration
- //we will use only the first creation run
- super.onUpdate(context, appWidgetManager, appWidgetIds);
- }
- }
And one last thing you must know for the beginning, there is a bug in android 1.5 that the onDeleted method is not called. The code below placed in the onRecive fixes the problem.
- if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
- final int appWidgetId = extras.getInt
- (AppWidgetManager.EXTRA_APPWIDGET_ID,
- AppWidgetManager.INVALID_APPWIDGET_ID);
- if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
- this.onDeleted(context, new int[] { appWidgetId });
- }
- } else {
- super.onReceive(context, intent);
- }
In the next weeks tutorial we will start coding the application.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@lendzEra (ledz motin)
BaconReader gets major update, adds Android Beam support, scrollable widget and more http://t.co/aTXFOvQb #android
6 min 6 sec ago -
@grenhall (Mattias Grenhall)RT @iphonecruncher2012HP finally caves and offers up TouchPad Kernel Source http://t.co/HwddIG75 #android #googleandroid #android #apps
6 min 9 sec ago -
@lendzEra (ledz motin)
Sony Tablet P started life as a wallet, almost ran Windows http://t.co/qgi6Nrrs #android
6 min 9 sec ago -
@onebadcarr2 (chris)I've just received an achievement: Quick https://t.co/GfeDIsJo #Android #Androidgames
6 min 10 sec ago -
@darren3131 (darren)I've just received an achievement: Logistician https://t.co/Dn9r87yG #Android #Androidgames
6 min 12 sec ago
Poll
Useful resources
Android Development Projects
- Android App wanted immediately by JoePublic
- LIST DATA PROJ by nhammoud
- Nonpublic project #1433932 by subpariq
- Alarm Android Application Design by globalheed
- Simple Album App for Android by ayfonfan
- iOS and Android photo manipulation 'Morph App' by whatwedomedia
- Onsite Software Engineers in Germany by sudhirshree
- Augmented reality by merder99
- Nonpublic project #1433560 by vobla73
- Mobile app coder needed for quick, simple app by Ergometrix




Comments
دردشة سورية دردشة
دردشة سورية
دردشة لبنانية
دردشة عراقية
شات سوري
شات لبناني
دردشة سوريا
دردشة لبنان
شات سوريا
شات لبنان
دردشة السويدي
منتديات السويدي
اغاني عراقية
صور فنانين
الرياضة العراقية
شعراء العراق
نغمات عراقية
اغاني عربية
اغاني كردية
دردشة عراقية
دردشة بنات العراق
دردشة صبايا بغداد
دردشة البصره
دردشة بغداد
دردشة بغدادية
دردشة صبايا بغداد
دردشة شباب العراق
دردشة بنات العراق
دردشة الكرادة
دردشة دمشق
دردشة بيروت
دردشة حلب
دردشة حلب
دردشة عراقية
دردشة العراق
شات عراقي
جات عراقي
دردشه عراقيه
دردشة صبايا لبنان
دردشة بنات لبنان
As you can see here we set:
As you can see here we set:
•the widget size (you cant size it as you like, for details see App Widget Design Guidelines)
•the layout used
•the configuration activity mentioned before
•and the updateperiod
The update period is limited, for example in 1.5 it is said to refres every 30 min even if you set a shorter period.
If you set this an ACTION_APPWIDGET_UPDATE intent will be generated to perform the update.
If the device is asleep when it is time for an update then the device will wake up in order to perform the update.
Because the period can not be set as short as you like, and it wakes up the device we wont use it, we will generate the ACTION_APPWIDGET_UPDATE intents ourself using the AlarmManager class.
a b c d e f g h i j
============================== ===========================
ipad bag blog
Sutudeg Community
Education News
============================== ===========================
a visit b visit c visit d visit e visit f visit g visit h visit i visit j visit k visit l visit m visit n visit o visit p visit q visit r visit s visit t visit u visit v visit w visit x visit y visit z visit aa visit ab visit ac visit ad visit ae visit af visit ag visit ah visit ai visit aj visit ak visit al visit am visit an visit ao visit ap visit aq visit ar visit as visit at visit au visit av visit aw visit ax visit ay visit az visit ba visit bb visit bc visit bd visit be visit bf visit bg visit bh visit bi visit bk visit bl visit bm visit bn visit bo visit bp visit bq visit br visit bs visit bt visit bu visit bv visit bw visit bx visit by visit bz visit ca visit cb visit cc visit cd visit ce visit cf visit cg visit ch ci cj ck cl ccl cm cn co cp cq cr cs ct cu cv
============================== ===========================
شات صوتي | دردشة صوتية | كلام
شات صوتي
| دردشة صوتية
|
كلام
| شات كلام
|
دردشة كلام
| دردشة صوتية
|
شات صوتي
| شات
|
Chat Voice
| ahj w,jd
شات صوتي
| دردشة صوتية
|
شات صوتي
| دردشة صوتية
|
دردشه
| دردشة
|
صوتي
| صوتية
|
شات صوتي
| دردشة صوتية
|
شات صوتي
| دردشة صوتية
|
الكلام
| دردشه صوتيه
|
]v]am w,jdm
| ]v]ai w,jdi
شات صوتي
شات صوتي
شات صوتي
Batik
Very interesting articles. Great job done
batik
great and useful
thanks for your article its really great and useful
sportbike specifications SKEMA RANGKAIAN Electronic Circuit scolarship wireless car specifications gadget and computer car first look Motorcycle Modification sexi-stars. newlaptop circuits-audio electronic projects auto girl weapons system science kids gadget bikes walpaper mobil-wallpaper MODIFIKASI MOBIL plane-wallpaper celebsexypict artist-scandal sport-cars bikespict motor-modify sexi-model laptopharga gambar-artist fast-superbike autoshowmodel harga-kamera notebook-price diamonds-collections phones-gallery camera-prices home-pic audio-gallery autocarpict living-cares homes life-style
The Android Market doesn't
The Android Market doesn't allow users to easily filter applications based on their license status. As a result a number of projects maintain ad-hoc lists of free and open source software software around the web. In recent times a couple of application repository projects have been started that focus on providing alternatives to the default Android Market. So far coverage of all the available open source applications is still sporadic.
Valuable Source for Widget Develpoment
As the android phones become more and more popular, having the knowledge to develop a widget for androids have become a powerful tool. As a riverside lawyer I use an android phone which many different applications to keep me up to date on what is happening with bankruptcy laws.
توبيكات نونو توبيكات توبيكات
توبيكات نونو
توبيكات
توبيكات سعودي
توبيكات 2012
توبيكات بنات
العاب نونو
العاب
العاب بنات
games
شات لمني الصوتي
دردشة لمني الصوتية
شات صوتي لمني
شات صوتي
دردشة صوتية
دردشة
دردشه
شات سعودي
شات خليجي
سكر بنات
جات
شات صوتي سعودي خليجي
chat voice
ahj
خليجي الصوتي
سعودي الصوتي
دردشة صوتي
شات صوتي
دردشة صوتية
شات كتابي
شات كتابي خليجي
شات عسل الصوتي
دردشة كتابية
chat
سعودي كول
سعودي كول 6666
كول
سعودي
سعودي كول انحراف
سعودي كول بنات
سعودي كول 1994
chat saudi col
شات سعودي كول
سعودي انحراف
سعودي انحراف2010
سعودي انحراف الصوتي
شات سعودي انحراف
دردشة سعودي انحراف
سعودي انحراف الصوتية
شبكة سعودي انحراف
سعودي انحراف الاصلي
سعودي انحراف كول
سعودي انحراف 2010
انحراف سعودي
saudideviation
دردشة صوتية سعوديه
دردشة صوتية سعودية
دردشة كتابية
دردشة كتابية خليجية
شات
دردشة
خاص للبنات
عرب ذوق
عرب ذوق الصوتي
عرب ذوق الصوتية
دردشة عرب ذوق
شات عرب ذوق
شبكة عرب ذوق
شات صوتي بنات
شات بنات الصوتي
دردشة بنات الصوتي
Girls Chat
شبكة عفناك
صوتية عفناك
شات عفناك
دردشة عفناك
عفناك الصوتي
دردشة عفناك
الخيال
الخيال كام
شبكة الخيال
الخيال الصوتي
الخيال الصوتية
دردشة الخيال
الخيال الصوتية
دردشة صوتية الخيال
شات سعودي خليجي
منتدى نونو
منتدى
منتديات
موقع
شبكة
نونو
Chat Nono
ahj w,jd
]v]am w,jdm
دليل مواقع ويب
دليل مواقع
دليل
مواقع
بنت كول
بنت كول الصوتي
شات بنت كول
دردشة بنت كول
شات بنت كول الصوتية
بنت كول الصوتيه
سعودي كول
صوتية سعودي كول
شات سعودي كول
دردشة سعودي كول
سعودي كول الصوتي
سعودي كول 6666
سعودي كول6666
سكر بنات
شات صوتي زين
شات صوتي ملوك
شات صوتي سعودي
شاتات صوتيه
مكتبة ماسنجر
شات صوتي حبي
شات صوتي كويت
YouTube - Broadcast Yourself. , اليوتيوب نونو
صيف كام
شات صوتي كول
شات انحراف
وه بس
خريطة الموقع نونو
الرياض كول الصوتي
كامات 6666
شات المها
كامات6666
شات كامات 6666
كامات 666
كامات 66
سعودي انحراف
شاتكامات6666
سعودي احوه
شات سعودي احوه
سعودي احوه الصوتي
سعودي احوه كول
دردشة سعودي احوه
احوه سعودي
بنات احوه
دبي الصوتي
سعودي في اي بي الصوتي
شبكة الرياض الصوتي
روعة الليل
لايف كام
الخليج كام
شات كان زمان الصوتي
شات صوتي قصيمي
شات قلبي
ارجوان
شات صوتي قطري
بدور الخليج
منتدى روح
شبكة روح
روح ديزاين
تحميل ماسنجر بلس
توبيكات حزينه
توبيكات
ماسنجر
ماسنجر بلس
تحميل ماسنجر
توبيكات رومنسيه
منتديات روح
دردشة
شات سعودي
خليجي
شات صوتي
توبيك
موقع توبيكات
سعودي كول 6666
سعودي انحراف 2011
سعودي كول
سعودي انحراف
Property Investment
In the architecture of widgets a "configuration" activity can be defined exactly for this, so we will not need the application to have a launcher activity, if there is a configuration defined it will automatically launched when a new widget is placed on the home screen. Property Investment
Real Estate Rebate
Nice widget examples, It's very helpful to develop the widget. Thanks for sharing this information.
Rebate Realtor
I found the perfect place for
I found the perfect place for my needs. Contains wonderful and useful messages. I have read most of them and has a lot of them. To me, he's doing the great work. frigidaire dehumidifier || Get your Ex Back
Taylor Lautner Topless
I have found this your post because I have been searching for some information about it almost three hours. You helped me a lot indeed and reading this your article I have found many new and useful information Taylor Lautner Topless
Le drapeau breton. Le symbole
Le drapeau breton. Le symbole de la Bretagne. Egalement nommé Gwenn Ha Du, qui signifie noir et blanc en breton drapeau breton Le drapeau breton. Le symbole de la Bretagne. Egalement nommé Gwenn Ha Du, qui signifie noir et blanc en breton Le symbole de la Bretagne. Egalement nommé Gwenn Ha Du, qui signifie noir et blanc en breton Le symbole de la Bretagne. drapeau breton fanion breizh étendard breton
appwidget
The update period is limited, for example in 1.5 it is said to refres every 30 min even if you set a shorter period.
If you set this an ACTION_APPWIDGET_UPDATE intent will be generated to perform the update.
If the device is asleep when it is time for an update then the device will wake up in order to perform the update.
Because the period can not be set as short as you like, and it wakes up the device we wont use it, we will generate the ACTION_APPWIDGET_UPDATE intents ourself using the AlarmManager class.
a b c d e f g h i j
Informative article
it is an Informative article, thanks for sharing.
Solitaire
Yes, I truly agree. I just
Yes, I truly agree.
I just bought my new android phone and I would like to learn how to build widgets. I find it fascinating to learn all the Android API.
Besides that, I spend my time with my site refrigerator review.
android
Most of the applications has a launcher activity, and the running begins with that, but its not necessary to have one. If you don't have one, the application wont show among the other installed programs giving the user the opportunity to run it. f
Nice widget examples, their
Nice widget examples, their pretty important when developing android apps as I recently figured out!
beads
widget new
Here we set the CountWidget class to capture the APPWIDGET_UPDATE intent and attach the previously described metadata xml to it.
The system automatically cares about to the DELETE, ENABLE and DISABLE broadsets get captured too.
Now create the CountWidget class which implements the AppWidgetProvider.
At firs lest see the empty methods that we can owerride from the AppWidgetProvider.
In the comments I explain what they are used for.
a b c d e
A friend of mine advised this
A friend of mine advised this site. And yes. it has some useful pieces of information and I enjoyed reading it. Therefore i would love to drop you a quick note to express my thanks. Take care
Riverside criminal defense attorney
Application
making widgets and applications for android it's so hard. Thanks to blogs like this we can improve our knowledge on android systems. As always, great post!
Mercedes GLK
I am a new comer to this
I am a new comer to this website! But i find it is really useful here! Thanks for sharing all this views and i do appreciate your time for posting such good article!
GSM Kampanya | Bilişim Teknoloji | Cep Telefonu | Turkcell Kampanyaları | Avea Kampanyaları | Vodafone Kampanyaları
Le message est écrit en très
Le message est écrit en très bonne manière et qu'elle comporte de nombreuses informations utiles pour moi. Je suis heureux de trouver votre manière distinguée de la rédaction du post. Maintenant, vous le rendre facile pour moi de comprendre et mettre en œuvre le concept. Beauty salon Merci pour le post
I just passed this onto a
I just passed this onto a colleague who was doing a little research on that. And he actually bought me lunch because I found it for him smile So let me rephrase that: i casino su gamblingportal
Good work by the blogger,
Good work by the blogger, Thanks a lot for the wonderful share.. Keep it up
windows vps | forex vps
تسريحات منتديات مكياج ازياء
تسريحات منتديات مكياج ازياء رسائل وسائط مسجات توبيكات وظيفة وظائف ديكور بلايز رجيم رشاقة حلويات معجنات نكت ديكورات لاين سبورت رمزيات صور رمزيه توبيكات ملونه صور العاب
Great
Hmm interesting, thanks for providing the coding examples! not too sure i can get my head around this though, its tough stuff. Will keep trying though i think and of by the way, thanks for all these tutorials!
Tips dan Informasi
Well, I am so excited that I
Well, I am so excited that I have found this your post because I have been searching for some information about it almost three hours. You helped me a lot indeed and reading this your article I have found many new and useful information about this subject. the diet solution
Hmm interesting, thanks for
Hmm interesting, thanks for providing the coding examples! not too sure i can get my head around this though, its tough stuff. Will keep trying though i think and of by the way, thanks for all these tutorials!
Peter, from greenhouses salisbury
We can give them a good
We can give them a good education that they can use in their life to get a better chance in this life. Im sure with a good education all of us will see the changing that all that kids can have. Mac DVD Ripper
Companies these days are
Companies these days are using ergonomic furniture to ensure that there are no injuries from work related hazards. Use an ergonomic chair and feel better comfort in your back and shoulder. rabattkod
Informative Post
Informative post, I like the article.
doubledome.com
appWidget
nice tutorial it was helpful as i am new to Android
and also can u give me idea to display multiple widgets on he home screen
from different application(example:from customized home application i have to display
widgets in place of icons for diff apps)think i have cleared
an idea could be helpful
thanx in advance
it is sometimes hard to
it is sometimes hard to Pandora in a world of adults Pandora Bracelets
Wow I really Want to develop
Wow I really Want to develop a widget and i am trying hard on it.Thanks for sharing this info.
Social Networking
Great Post!
Hello! Just dropping by to let you know we featured this post in SoftCity's roundup on application development. Thanks for the great info and links!
http://cafe.softcity.com/artic le/view/5MjMxMzN/mobile-applic ation-develo...
Go widgets
Nice widget examples, their pretty important when developing android apps as I recently figured out!
vitamin b12 deficiency symptoms
Pop Art
I am a new comer to this website! But i find it is really useful here! Thanks for sharing all this views and i do appreciate your time for posting such good article!
Pop Art
Popart