Pro Android with Kotlin


CHAPTER 6: Content Providers


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

66
CHAPTER 6: Content Providers
abstract fun delete(
uri:Uri,
selection:String,
selectionArgs:Array) : Int
These are the parameters and their meanings:

uri: This specifies the type coordinates of the data in the data space. 
Content consumers will tell what kind of data they are targeting by 
appropriately specifying this parameter. Note that for deleting or 
updating single data sets, it is generally assumed that the URI contains 
the (technical) ID of the datum at the end of the URI path, for example, 
content://com.android.contacts/contact/42.

values: These are the values to be inserted or updated. You use the 
various get*() methods of this class to access the values.

selection: This specifies a selection for the data to be updated or 
deleted. The content provider framework makes no assumptions 
how this selection parameter must look. It is completely up to the 
implementation, and content requesters must yield to what the 
implementation defines. In many cases, you will, however, have 
something like a SQL selection string such as name = Jean AND age < 
45 here. If null, all items of the data set will be addressed.

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 for SQL. It may be null if there are no selection placeholders.
The insert() method is supposed to return the URI specifying the inserted data. This return 
value may be null, so there is no strict requirement to return something here. If it returns 
something, this should contain the technical ID. All the Int-returning methods are supposed 
to return the number of affected data sets.
If you don’t want the content provider to be able to alter any data, you can just provide empty 
implementations to all the insert, update, and delete methods, and let them return 0 or null.
Finishing the ContentProvider Class
To finish the implementation of your ContentProvider class, you must implement one more 
method in addition to the query, insert, update, and delete methods.
abstract getType(uri:Uri) : String
This maps any usable URI to the appropriate MIME type. For a possible implementation, you 
can, for example, use URIs as follows:
ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.."
ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd..< type>"



Download 5.42 Mb.

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




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