Building a Live Folder

Now that you know what live folders are, you can learn to build one. After that, you'll learn how to drag an icon onto the home page to use that live folder. We will also show you how the "live" part works.

To build a live folder, you need two things: an activity and a content provider. The activity is responsible for creating the live folder on the home page. The content provider is responsible for returning a cursor that conforms to a live-folder contract. Typically, you package these two entities in an application and then deploy that application onto the device. You will also need some supporting files to make all this work. We will explain and demonstrate these ideas using a sample, which contains the following files:

• AndroidManifest.xml: This file defines which activity needs to be called to create the definition for a live folder.

• This activity is responsible for supplying the definition for a live folder that can display all contacts in the contacts database.

• This content provider will respond to the live-folder URI that will return a cursor of contacts. This provider internally uses the contacts content provider that ships with Android.

• This is a specialized cursor that knows how to perform a requery when underlying data changes.

• This file is needed by MyCursor to orchestrate the requery.

• This simple activity is needed for the creation of an Android project.

We'll describe each of these files to give you a detailed understanding of how live folders work.

0 0

Post a comment