The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Home Screen App Widgets

App widgets are live elements that the user can add to her home screen. Android ships with a variety of app widgets, such as a music player, and device manufacturers frequently add more. However, developers can add their own — in this chapter, we will see how this is done.

For the purposes of this book, “app widgets” will refer to these items that go on the home screen. Other uses of the term “widget” will be reserved for the UI widgets, subclasses of View, usually found in the android.widget Java package.

Prerequisites

Understanding this chapter requires that you have read the core chapters, particularly the chapters on:

App Widgets and Security

Creating app widgets looks little like creating an activity. That is because the home screen is showing your app widget, whereas your own app shows your own activities. Having a third-party app (a home screen) show a UI from your app has some security ramifications.

Android’s security model is based heavily on Linux user, file, and process security. Each application is (normally) associated with a unique user ID. All of its files are owned by that user, and its process(es) run as that user. This prevents one application from modifying the files of another or otherwise injecting their own code into another running process. It would be dangerous for the home screen to run arbitrary code itself or somehow allow its UI to be directly manipulated by another process.

The app widget architecture, therefore, is set up to keep the home screen application independent from any code that puts app widgets on that home screen, so bugs in one cannot harm the other.

The Big Picture for a Small App Widget

The preview of this section may contain nuts.

Crafting App Widgets

The preview of this section is being chased by zombies.

Another and Another

The preview of this section may contain nuts.

App Widgets: Their Life and Times

The preview of this section was eaten by a grue.

Controlling Your (App Widget’s) Destiny

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

One Size May Not Fit All

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

Lockscreen Widgets

The preview of this section was lost due to a rupture in the space-time continuum.

Preview Images

The preview of this section was stepped on by Godzilla.

Being a Good Host

The preview of this section is in the process of being translated from its native Klingon.