Saving Data on Android



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

ToDoDbSchema
 or the new 
ToDoContract
, choose 
ToDoContract
. The goal is to have the content provider depending on the 
contract so that it serves as an abstract layer above the database handler. This 
design allows for the data source to be swapped out as long as it meets the 
same specifications as the previous data source, and no other code that is 
dependent on the database will be affected, in this app or other apps that 
utilize the contract.
Open up the file you just created in the 
provider
 package called 
ToDoContentProvider.kt
. There are six 
TODO
 tags, one for each method that is 
required to implement. Notice how the class inherits from the 
ContentProvider
 
class in the Android SDK. Before implementing the methods, add the following 
declarations inside the class above all the overridden method stubs:
  
// 1
 
  
// This is the content provider that will
 
  
// provide access to the database
 
  
private
 
lateinit
 
var
 db : ToDoDatabaseHandler 
  
private
 
lateinit
 
var
 sUriMatcher : UriMatcher 
 
  
// 2
 
  
// Add the URI's that can be matched on
 
  
// this content provider
 
  
private
 
fun
 
initializeUriMatching
()
 { 
 
    sUriMatcher = UriMatcher(UriMatcher.NO_MATCH) 
    sUriMatcher.addURI(AUTHORITY,CONTENT_PATH, 
URI_ALL_ITEMS_CODE) 
    sUriMatcher.addURI(AUTHORITY, CONTENT_PATH + 
"/#"

URI_ONE_ITEM_CODE) 
    sUriMatcher.addURI(AUTHORITY, CONTENT_PATH + 
"/"
 + COUNT, 
Saving Data on Android
Chapter 4: ContentProvider
raywenderlich.com
81


                       URI_COUNT_CODE) 
  } 
 
  
// 3
 
  
// The URI Codes
 
  
private
 
val
 URI_ALL_ITEMS_CODE = 
10
 
  
private
 
val
 URI_ONE_ITEM_CODE = 
20
 
  
private
 
val
 URI_COUNT_CODE = 
30
1. Add an instance of the database handler as the content provider sits between the 
database and the rest of the program, also create a URI matcher to help construct 
the URI strings.
2. Create a function called 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   87   88   89   90   91   92   93   94   ...   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