App widgets

From Android Wiki

Jump to: navigation, searcha

App widgets allow you to define custom displays (e.g. weather, news ticker etc) that the user can place on a Launcher screen. But because these widgets are running in the context of the Launcher, not directly in your own app, there are some limitations:

  • The kinds of UI widgets you can create are restricted to those supported by the RemoteViews class. You cannot use custom UI widgets, or custom subclasses of the supported widgets. The supported widget classes do not include SurfaceView or its GLSurfaceView subclass, so high-frame-rate animated displays and OpenGL animations are not really feasible. You can do periodic updates of the widget display with any frequency you desire, but it is probably wise not to make this too resource-intensive, because of the amount of interprocess communication and context-switching required.
  • If you want to interact with the user, this has to be done by attaching a PendingIntent to be triggered when the user taps a widget. This then sends an Intent back to the BroadcastReceiver in your app that is responsible for handling the app widget.

The framework supplies AppWidgetProvider, which is a BroadcastReceiver subclass to make it easier to implement an app widget provider. But it is not a requirement to use this.

Sample Code

Personal tools