Книга: Beginning Android

Getting a Handle

Getting a Handle

Where do these Uri instances come from?

The most popular starting point, if you know the type of data you want to work with, is to get the base Uri from the content provider itself in code. For example, CONTENT_URI is the base Uri for contacts represented as people — this maps to content://contacts/people. If you just need the collection, this Uri works as is; if you need an instance and know its identifier, you can call addId() on the Uri to inject it, so you have a Uri for the instance.

You might also get Uri instances handed to you from other sources, such as getting Uri handles for contacts via sub-activities responding to ACTION_PICK intents. In this case, the Uri is truly an opaque handle… unless you decide to pick it apart using the various getters on the Uri class.

You can also hard-wire literal String objects and convert them into Uri instances via Uri.parse(). For example, in Chapter 25, the sample code used an EditText with content://contacts/people pre-filled in. This isn’t an ideal solution, as the base Uri values could conceivably change over time.

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


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