Pro Android with Kotlin


CHAPTER 6: Content Providers


Download 5.42 Mb.
Pdf ko'rish
bet62/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   58   59   60   61   62   63   64   65   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

65
CHAPTER 6: Content Providers

selectionArgs: The selection parameter may contain placeholders like ?. 
If so, the values to be inserted for the placeholders are specified in this 
array. Again, the framework makes no strict assumptions here, but in 
most cases the ? serves as a placeholder, as in name = ? AND age < ?, 
like in SQL. This may be null if there are no selection placeholders.

sortOrder: This is only for variants A and B. This specifies a sort order 
for the data to be returned. The content provider framework does not 
prescribe a syntax here, but for SQL-like access, this will usually be 
something like name DESC, or ASC.

queryArgs: This is only for variant C. All three selections, selection 
arguments, and sort order may or may not be specified using an 
android.os.Bundle object. By convention, for SQL-like queries, the 
bundle keys are as follows:

ContentResolver.QUERY_ARG_SQL_SELECTION

ContentResolver.QUERY_ARG_SQL_SELECTION_ARGS

ContentResolver.QUERY_ARG_SQL_SORT_ORDER

cancellationSignal: This is only for variants B and C. If this is not null, 
you can use it to cancel the current operation. The Android OS will then 
appropriately inform the requesters.
All the query methods are supposed to return an android.database.Cursor object. This 
allows you to iterate over the data sets, with the convention that each data set contains 
an _id keyed technical ID. See “A Cursor Class Basing on AbstractCursor” and “Designing 
Content URIs” in the “Providing Content” section below to learn how to design appropriate 
cursor objects.
Modifying Content
Content providers do not just allow you to read content, they also allow you to alter content. 
For this aim, the following methods exist:
abstract fun insert(
Uri uri:Uri,
values:ContentValues) : Uri
// You don't have to overwrite this, the default
// implementation correctly iterates over the input
// array and calls insert(...) on each element.
fun bulkInsert(
uri:Uri,
values:Array) : Int
abstract fun update(
uri:Uri,
values:ContentValues,
selection:String,
selectionArgs:Array) : Int



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   58   59   60   61   62   63   64   65   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling