Saving Data on Android


Reading the user preferences



Download 19,28 Mb.
Pdf ko'rish
bet50/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   46   47   48   49   50   51   52   53   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Reading the user preferences
Currently, 
getNoteSortOrder()
 returns the default value of 
NoteSortOrder.FILENAME_ASC
. Replace the returned value with the following:
NoteSortOrder.valueOf( 
  sharedPrefs.getString(KEY_NOTE_SORT_PREFERENCE, 
DEFAULT_SORT_ORDER) 
      ?: DEFAULT_SORT_ORDER 
)
The above code uses 
getString()
 to retrieve the sort order the user stored, or 
FILENAME_ASC
 as the default value if the key 
KEY_NOTE_SORT_PREFERENCE
 does not 
exist.
Next, write the function to read the priority filters. Right now 
getNotePriorityFilters()
 returns an empty 
Set
. Replace 
setOf()
 with the 
following:
sharedPrefs.getStringSet(KEY_NOTE_PRIORITY_SET, 
setOf(DEFAULT_PRIORITY_FILTER)) 
      ?: setOf(DEFAULT_PRIORITY_FILTER)
The code above reads a 
Set
 of 
String
s from the prefs with the key 
KEY_NOTE_PRIORITY_SET
, and if nothing is found with that key, it will use a set with 
the priority of 
"1"
 inside, as the default.
Now that the functions to read and write the sort order and priority filters are 
written, you can use these functions in the 
MainActivity
.
Saving Data on Android
Chapter 2: Shared Preferences
raywenderlich.com
45



Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   46   47   48   49   50   51   52   53   ...   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