Saving Data on Android


droidquiz  — and name  it  QuizApplication



Download 19,28 Mb.
Pdf ko'rish
bet130/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   126   127   128   129   130   131   132   133   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

droidquiz
 — and name 
it 
QuizApplication
.
Saving Data on Android
Chapter 6: Entity Definitions
raywenderlich.com
115


Replace everything inside the 
QuizzApplication
 class with the following:
class
 
QuizApplication
 : 
Application
() { 
  
// 1
 
  
companion
 
object
 { 
    
lateinit
 
var
 database: QuizDatabase 
// 2
 
      
private
 
set
 
  } 
 
  
override
 
fun
 
onCreate
()
 { 
    
super
.onCreate() 
    database = Room 
        .databaseBuilder( 
            
this

            QuizDatabase::
class
.
java

            
"quiz_database"
 
        ) 
// 3
 
        .build() 
  } 
}
Taking each commented section in turn:
1. Makes this class extend 
Application
, so that it runs with the app launch.
2. Creates a private database property that will hold a reference to your Room 
database.
3. The 
databaseBuilder()
 method creates an instance of your Room database at 
runtime. The first parameter accepts a 
Context
 instance. The second parameter 
expects the class that you annotated as your Room database. The third parameter 
allows you to define a name for your SQLite database.
Now, add your 
QuizApplication
 class to your manifest file by adding the following 
attribute to your application tag inside your 

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   126   127   128   129   130   131   132   133   ...   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