Whats In This Chapter

> Creating home screen Widgets

> Implementing Live Folders

> Adding search to your applications

> Surfacing search results to the Quick Search Box

> Creating Live Wallpaper

Widgets, Live Folders, Live Wallpaper, and the Quick Search Box let you own a piece of the user's home screen, providing either a window to your application or a stand-alone source of information directly on the home screen. They're an exciting innovation for users and developers, providing the following:

> Users get instant access to interesting information without needing to open an application.

> Developers get an entry point to their applications directly from the home screen.

A useful widget, Live Folder, or dynamic wallpaper decreases the chance that an application will be uninstalled, and increases the likelihood of its being used.

With such power comes responsibility. Widgets run constantly as subprocesses of the home-screen process. You need to be particularly careful when creating widgets to ensure they remain responsive and don't drain system resources.

This chapter demonstrates how to create and use App Widgets, Live Folders, and Live Wallpaper detailing what they are, how to use them, and some techniques for incorporating interactivity into these application components.

It also describes how to integrate the Android search framework into your application and surface search results to the Quick Search Box.


Widgets, more properly AppWidgets, are visual application components that can be added to other applications. The most notable example is the default Android home screen, where users can add widgets to their phone-top, though any application you create can become an AppHost and support third-party widgets if you desire.

Widgets enable your application to own a piece of interactive screen real estate, and an entry point, directly on the user's home screen. A good App Widget provides useful, concise, and timely information with a minimal resource cost.

Widgets can be either stand-alone applications (such as the native clock) or compact but highly visible components of larger applications — such as the calendar and media player widgets.

Figure 10-1 shows four of the standard home-screen widgets available on Android devices: the search box, power control, news and weather, and media player.


To add a widget to the home screen, long-press a piece of empty space and select Widgets. You will be presented ivith a list of available ividgets. Once you've added one you can move it by long-pressing it and dragging it around the screen. Remove widgets by dragging them into the garbage can icon at the bottom of the screen.

Widgets embedded into the home screen are hosted within the home screen's process. They will wake the device based on their update rates to ensure each widget is up to date when it is visible. As a developer, you need to take extra care when creating your widgets to ensure that the update rate is as low as possible, and that the code executed within the update method is lightweight.

The following sections show how to create widgets and describe some best practices for performing updates and adding interaction.


App Widgets are implemented as intentReceivers. They use RemoteViews to update a view hierarchy hosted within another application process; in most cases that host process is the home screen.

Prepared for ASHLEE KABAT, email: [email protected] Order number: 56760408 This PDF is for the purchaser's personal use in accordance with the Wrox Terms of Service and under US copyright as stated on this book's copyright page. If you did not purchase this copy, please visit www.wrox.com to purchase your own copy.

To create a widget for your application you need to create three components:

1. A layout resource that defines the UI for the widget

2. An XML definition file that describes the metadata associated with the widget

3. An Intent Receiver that defines and controls the widget

You can create as many widgets as you want for a single application, or have an application that consists of a single widget. Each widget can use the same size, layout, refresh rate, and update logic, or they can all use different ones. In many cases it can be useful to offer multiple versions of your widgets in different sizes.

Was this article helpful?

0 0
Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment