Книга: Beginning Android

Step #3: Declare the Properties

Step #3: Declare the Properties

Remember those properties you referenced when you were using a content provider in the previous chapter? Well, you need to have those too for your own content provider.

Specifically, you want a public static class implementing BaseColumns that contains your property names, such as this example from Provider:

public static final class Constants implements BaseColumns {
 public static final Uri CONTENT_URI =
  Uri.parse("content://com.commonsware.android.constants.Provider/constants");
 public static final String DEFAULT_SORT_ORDER = "title";
 public static final String TITLE = "title";
 public static final String VALUE = "value";
}

If you are using SQLite as a data store, the values for the property name constants should be the corresponding column name in the table, so you can just pass the projection (array of properties) to SQLite on a query(), or pass the ContentValues on an insert() or update().

Note that nothing in here stipulates the types of the properties. They could be strings, integers, or whatever. The biggest limitation is what a Cursor can provide access to via its property getters. The fact that there is nothing in code that enforces type safety means you should document the property types well so people attempting to use your content provider know what they can expect.

Оглавление книги


Генерация: 1.056. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз