0
0
Android Kotlinmobile~5 mins

SharedPreferences / DataStore in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is SharedPreferences used for in Android?
SharedPreferences is used to store small amounts of simple data as key-value pairs, like user settings or preferences, that persist across app launches.
Click to reveal answer
intermediate
What is the main advantage of DataStore over SharedPreferences?
DataStore is more modern, supports asynchronous and type-safe data storage, and avoids blocking the main thread, making it safer and more efficient for storing data.
Click to reveal answer
beginner
How do you save a string value using SharedPreferences in Kotlin?
Use edit() to get an editor, then putString(key, value), and finally apply() to save asynchronously.
Click to reveal answer
intermediate
What are the two types of DataStore in Android?
Preferences DataStore (stores key-value pairs without a predefined schema) and Proto DataStore (stores typed objects using Protocol Buffers).
Click to reveal answer
beginner
Why should you avoid using SharedPreferences on the main thread?
Because SharedPreferences can block the main thread during read/write operations, causing the app UI to freeze or lag.
Click to reveal answer
Which method is used to save changes in SharedPreferences asynchronously?
Astore()
Bcommit()
Capply()
Dsave()
What is a key benefit of using DataStore over SharedPreferences?
ANo need to define keys
BOnly stores strings
CBlocks the main thread
DSupports asynchronous operations
Which DataStore type uses Protocol Buffers for data storage?
APreferences DataStore
BProto DataStore
CSharedPreferences
DSQL DataStore
How do you read a value from SharedPreferences?
AgetString(key, defaultValue)
BreadString(key)
CfetchString(key)
DloadString(key)
Which of these is NOT a recommended practice when using SharedPreferences?
AStore large binary files
BUse apply() for saving changes
CAvoid blocking the main thread
DStore simple key-value pairs
Explain how to save and retrieve a user preference using SharedPreferences in Kotlin.
Think about how you store and read simple settings like a username.
You got /4 concepts.
    Describe the differences between Preferences DataStore and Proto DataStore and when to use each.
    Consider the complexity and type safety of your data.
    You got /4 concepts.