Working with App Widgets in Android

In Android, app widgets (also known as Home screen widgets) are miniature applications that can be embedded within other applications, such as the Home screen. App widgets normally resemble small icons or very small views on your Home screen, and they allow users to interact with your application by simply tapping them.

These app widgets can accept user input through click events and can update themselves on a regular schedule. App widgets are applied to the Home screen by long-pressing (pressing on the screen for a couple of seconds) and then selecting widgets, as shown in Figure 8-1.

To make the Screen Brightness Toggle application more usable, I show you how to build an app widget for the application so that users can add it to their Home screen. After adding the widget, the user can tap it to activate the app's core functionality and toggle the screen brightness mode — without first having to open the application. The widget also updates its layout to inform the user what state the device is in, as shown in Figure 8-2.

Working with remote views

Because Android is based on the Linux 2.6 kernel, the Android platform inherits security idioms from Linux. For example, the Android security model is heavily based around the Linux user, file, and process security model.

image Accordingly, each application in Android is (usually) associated with a unique ...

Get Android™ Tablet Application Development For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.