Android Development Android Data Storage 1 — Questions and Answers
Question 1: Which Android Jetpack library provides an abstraction layer over SQLite for local data persistence?
- Room (Correct answer)
- DataStore
- LiveData
- SQLiteOpenHelper
Correct answer: Room
Room is a persistence library that provides compile-time verification of SQL queries and abstracts SQLite database access.
Question 2: What annotation marks a class as a Room database entity?
- @Entity (Correct answer)
- @Table
- @DatabaseObject
- @Model
Correct answer: @Entity
The @Entity annotation marks a Kotlin or Java class as a Room database table, with each field mapping to a column.
Question 3: Which Room annotation is used to define data access methods?
- @Dao (Correct answer)
- @Repository
- @Query
- @Database
Correct answer: @Dao
@Dao marks an interface or abstract class as a Data Access Object, which contains methods for interacting with the database.
Question 4: What is the purpose of SharedPreferences in Android?
- To store small amounts of primitive key-value data persistently (Correct answer)
- To share data between apps
- To store large files
- To manage user accounts
Correct answer: To store small amounts of primitive key-value data persistently
SharedPreferences provides a mechanism for storing and retrieving small amounts of primitive data as key-value pairs that persist across app sessions.
Question 5: Which Jetpack component is the recommended replacement for SharedPreferences?
- DataStore (Correct answer)
- Room
- WorkManager
- LiveData
Correct answer: DataStore
Jetpack DataStore is the recommended replacement for SharedPreferences, offering asynchronous, consistent, and transactional data storage.
Question 6: What does WAL mode stand for in SQLite?
- Write-Ahead Logging (Correct answer)
- Write Access Lock
- Web API Layer
- Write and Load
Correct answer: Write-Ahead Logging
WAL (Write-Ahead Logging) mode in SQLite allows concurrent reads and writes, improving performance in multi-threaded apps.
Which Android Jetpack library provides an abstraction layer over SQLite for local data persistence?