Search This Blog

Tuesday 17 April 2012

Home screen widget , Weather widget in android

Home-Screen widget are best when your application is running in background and you want to show progress update and related information on home screen.
For example-You are playing song in MediaPlayer and want to show progress on home screen about currently playing song and other information

So for this we need three classes and in the end of this article i have posted full source code link

  • WeatherDataProvider — Our ContentProvider which stores the weather data for this sample. Note that for simplicity, it currently stores the data in memory as opposed to an external and persistent storage such as a file, network location, database, or shared preference.
  • WeatherWidgetProvider — Our AppWidgetProvider which handles specific intent actions (such as when an item is clicked, or the refresh button is pressed). It also sets up the RemoteViews for the widget and binds the service to the collection view in the widget.
  • WeatherWidgetService — Our RemoteViewsService which manages the creation of new factories, which return the RemoteViews for each item in the ListView.   
Screen shot of this application will be like that

Note- This project is for android API version 3.0 and above so make sure your project have this level of API else it will show error

When you will run this.It has no launcher activity so it will give any out put.It will just show in console following message

[2012-04-17 17:43:41 - WeatherWighet] Android Launch![2012-04-17 17:43:41 - WeatherWighet] adb is running normally.[2012-04-17 17:43:41 - WeatherWighet] No Launcher activity found![2012-04-17 17:43:41 - WeatherWighet] The launch will only sync the application package on the device![2012-04-17 17:43:41 - WeatherWighet] Performing sync[2012-04-17 17:43:41 - WeatherWighet] Automatic Target Mode: using existing emulator 'emulator-5556' running compatible AVD 'android_14.0'[2012-04-17 17:43:41 - WeatherWighet] Uploading WeatherWighet.apk onto device 'emulator-5556'[2012-04-17 17:43:42 - WeatherWighet] Installing WeatherWighet.apk...[2012-04-17 17:43:46 - WeatherWighet] Success![2012-04-17 17:43:46 - WeatherWighet] /WeatherWighet/bin/WeatherWighet.apk installed on device[2012-04-17 17:43:46 - WeatherWighet] Done!

That is means that your HomeScreen widegt is can show it on your main screen

                                          Download complete Source code


  1. Though I had written about Beginner Android Tutorial using Eclipse but this is mor advanced tutorial. Good work

  2. I am unable to run it. It says "Unfortunately the widget has stopped working". On debugging service class, cursor is coming out to be null. And on debugging widgetprovider class, intent is unable to locate the intent in its update method. PLease plaese help..


Feedback always help in improvement. If you have any query suggestion feel free to comment and Keep visiting my blog to encourage me to blogging

Android News and source code