15-Dec-11 (Created: 15-Dec-11) | More in 'Android Widgets'

The core idea of widgets in Android

Briefly, here is the core idea of how home screen widgets work (knowing this should make the rest of this section a bit easier to follow). An AppWidgetProvider is a broadcast receiver that gets invoked every once in a while based on a timer interval that you specify in a configuration file. This AppWidgetProvider then loads a RemoteViews instance based on a layout file. This RemoteViews object is then passed to the AppWidgetManager to be displayed on the home screen.

Optionally, you can tell Android that you have an activity that needs to be invoked before placing the widget for the first time on the home screen. This allows the configuration activity to set initialization parameters for the widget.

You also can set up onClick events on the remote views of the widget so that intents can get fired based on those events. These intents then can invoke whatever components necessary, including sending messages to the AppWidgetProvider broadcast receiver.

At a high level, this is all there is to home screen widgets. The rest is the mechanics and variations on each of these basic ideas.