Saving Data on Android


com.raywenderlich.contentprovidertodo.Controller



Download 19,28 Mb.
Pdf ko'rish
bet87/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   83   84   85   86   87   88   89   90   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

com.raywenderlich.contentprovidertodo.Controller
 folder and select 
new
 > 
package
. A dialog pops up prompting for the name of the new package, type in 
provider
 and click 
OK
.
Adding the contract class
Now add the 
ToDoContract.kt
 class. Right click the new 
provider
 package and 
select 
New
 > 
Kotlin File/Class
. In the resulting dialog enter the name 
ToDoContract
, for the "Kind" dropdown select "File" and press 
OK
. A Kotlin file will 
be created in the 
provider
 directory. Insert the following declarations into the 
Contract.kt
 file beneath the package declaration:
// The ToDoContract class
 
object
 ToDoContract { 
  
// 1
 
  
// The URI Code for All items
 
  const 
val
 ALL_ITEMS = 
-2
 
 
  
// 2
 
  
//The URI suffix for counting records
 
  const 
val
 COUNT = 
"count"
 
Saving Data on Android
Chapter 4: ContentProvider
raywenderlich.com
77


  
// 3
 
  
//The URI Authority
 
  const 
val
 AUTHORITY = 
"com.raywenderlich.contentprovidertodo.provider"
 
 
  
// 4
 
  
// Only one public table.
 
  const 
val
 CONTENT_PATH = 
"todoitems"
 
 
  
// 5
 
  
// Content URI for this table. Returns all items.
 
  
val
 CONTENT_URI = Uri.parse(
"content://
$AUTHORITY
/
$CONTENT_PATH
"

 
  
// 6
 
  
// URI to get the number of entries.
 
  
val
 ROW_COUNT_URI = Uri.parse(
"content://
$AUTHORITY
/
$CONTENT_PATH
/
$COUNT
"

 
  
// 7
 
  
// Single record mime type
 
  const 
val
 SINGLE_RECORD_MIME_TYPE = 
"vnd.android.cursor.item/
vnd.com.raywenderlich.contentprovidertodo.provider.todoitems"
 
 
  
// 8
 
  
// Multiple Record MIME type
 
  const 
val
 MULTIPLE_RECORDS_MIME_TYPE = 
"vnd.android.cursor.item/
vnd.com.raywenderlich.contentprovidertodo.provider.todoitems"
 
 
  
// 9
 
  
// Database name
 
  const 
val
 DATABASE_NAME: String = 
"todoitems.db"
 
 
  
// 10
 
  
// Table Constants
 
  
object
 ToDoTable { 
    
// The table name
 
    const 
val
 TABLE_NAME: String = 
"todoitems"
 
 
    
// The constants for the table columns
 
    
object
 Columns { 
      
//The unique ID column
 
      const 
val
 KEY_TODO_ID: String = 
"todoid"
  
      
//The ToDo's Name
 
      const 
val
 KEY_TODO_NAME: String = 
"todoname"
  
      
//The ToDo's category
 
      const 
val
 KEY_TODO_IS_COMPLETED: String = 
"iscompleted"
  
    } 
  } 
}
1. The constant 
ALL_ITEMS
 is the code used for the URI when the query method
Saving Data on Android
Chapter 4: ContentProvider
raywenderlich.com
78


should return all the items in the database.
2.
count
 is the suffix used on the URI when the count of items in the table is 
requested.
3.
AUTHORITY
 is the prefix of the URI that serves as the symbolic name for the 
provider.
4.
CONTENT_PATH
 corresponds to the name of the 
todoitems
 table.
5.
CONTENT_URI
 is created by concatenating the authority, or name of the 
provider with the path, or the name of the table. This is then parsed into a URI 
that is used to get all the records from the provider.
6.
ROW_COUNT_URI
 A second URI that utilizes the same authority but has the 
count content type. This URI is used to retrieve the number of records in the 
table.
7.

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   83   84   85   86   87   88   89   90   ...   292




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish