Exploring Live Folders

A live folder in Android is to a content provider what an RSS reader is to a publishing web site. Let us explain. We said in Chapter 3 that content providers are similar to web sites that provide information based on URIs. As web sites proliferated, with each publishing its information in a unique way, there arose a need to aggregate information from multiple sites so that a user could follow the developments through a single reader. To this end came the design of RSS. RSS forced us to see a common pattern among disparate sets of information. Having a common pattern lets you design a reader once and use it to read any type of content, as long as the content is presented in a uniform way.

Live folders are not that different in concept. As an RSS reader provides a common interface to published web-site content, a live folder defines a common interface to a content provider in Android. As long as the content provider can satisfy this protocol, Android can create a live folder on the device's home page to represent that content provider. When a user clicks this live folder, the system will contact the content provider. The content provider is then expected to return a cursor. According to the live-folder contract, this cursor must have a predefined set of columns. This cursor is then visually presented through a ListView or a GridView. Based on this common-format idea, live folders work like this:

1. First you create an icon on the home page representing a collection of rows coming from a content provider. You make this connection by specifying a URI along with the icon.

2. When a user clicks that icon, the system takes the URI and uses it to call the content provider. The content provider returns a collection of rows through a cursor.

3. As long as this cursor has columns expected by the live folder (such as name, description, and the program to invoke when that row is clicked), the system will present these rows as a ListView or a GridView.

4. Because the ListViews and GridViews are capable of updating their data when the underlying data store changes, these views are called "live"—hence the name "live folders."

So two key principles are at work in live folders. The first is the set of same column names across cursors. The second is that the views know how to look for any updates and change themselves accordingly. This second point is not unique to live folders, but quite natural to all views in the Android UI.

Now that you have some idea of what live folders are, we'll systematically explore the live-folder framework a bit more. We will do that in two subsections. In the first subsection, we will examine the overall end-user experience of a live folder. This should further solidify your understanding of the concept.

In the second subsection, we will show you how to build a live folder correctly so that it is actually "live." It does take some extra work to make a live folder "live," so we will explore this not-so-obvious aspect of live folders.

Was this article helpful?

0 0

Post a comment