Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet166/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   162   163   164   165   166   167   168   169   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Kotlin Coroutines
 or creating your own 
threads.
Next, change the 
deleteQuestions()
 to the following code:
override
 fun deleteQuestions() { 
  
AsyncTask
.execute { quizDao.clearQuestions() } 
}
Just like 
saveAnswer()
 and 
saveQuestion()
, this method uses an 
AsyncTask
 to 
execute one of your DAO's methods: 
clearQuestions()
. As the name implies
deleteQuestions()
 will delete all the questions in your database.
Finally, implement the remainder of the code like this:
override
 
fun
 
getSavedQuestions
()
 = allQuestions 
 
override
 
fun
 
getQuestionAndAllAnswers
()
 = 
allQuestionsAndAllAnswers
Once again, because you're using 
LiveData
, if you ever need to access fresh 
information from the database, you simply have to observe the preloaded 
LiveData

in your repository. And that is all you need to create a repository that interacts with 
your database using your Data Access Objects.
Saving Data on Android Chapter 9: Using Room with Google's Architecture Components
raywenderlich.com
154


At this point, you might be wondering: 
Why do I need to define a repository that 
interacts with my DAOs? Can't I simply use my DAOs inside my ViewModels?
Well, you certainly can use your DAOs directly inside your 
ViewModel
s, but you also 
need to remember a very important principle in programming: 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   162   163   164   165   166   167   168   169   ...   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