Friday, 26 February 2016

Widget: Steps to write a widget


  • Widgets are little applications which can be placed on the home screen of your Android device.
  • A widget gets its data on a periodic timetable. There are two methods to update a widget, one is based on an XML configuration file and the other is based on AlarmManager.

Steps to write a widget

  • Define a layout file for your widget. 
  • Maintain an XML file (AppWidgetProviderInfo) which describes the properties of the widget, e.g. size or fixed update frequency. 
  • Create a broadcast receiver which will be used to update the widget. This receiver extends AppWidgetProvider which provides additional lifecycle hooks for widgets. 
  • Maintain the App Widget configuration in the "AndroidManifest.xml" file. 
  • Optional, you can also specify a configuration activity which is called once when one instance of the widget is added to the homescreen.

No comments:

Post a Comment