AAD AAD Jetpack Libraries & Modern Android Development 2 — Questions and Answers
Question 1: What is the role of a Room Entity?
- It defines a table in the SQLite database (Correct answer)
- It handles network requests
- It observes LiveData updates
- It manages Fragment transactions
Correct answer: It defines a table in the SQLite database
A Room @Entity is a data class annotated to represent a table in the SQLite database, with each field mapping to a column.
Question 2: Which Jetpack Compose function is used to remember a mutable state variable across recompositions?
- stateOf()
- remember { mutableStateOf() } (Correct answer)
- liveDataOf()
- observeState()
Correct answer: remember { mutableStateOf() }
remember { mutableStateOf() } creates a state holder that Compose remembers across recompositions, triggering UI updates whenever the value changes.
Question 3: What does the @Composable annotation indicate in Jetpack Compose?
- The function runs on a background thread
- The function describes UI that Compose can render and recompose (Correct answer)
- The function is an extension of View
- The function is called only once at startup
Correct answer: The function describes UI that Compose can render and recompose
@Composable marks a function as a Compose UI function that describes part of the UI tree and can be recomposed by the Compose runtime when state changes.
Question 4: Which WorkManager constraint ensures a task only runs when the device is connected to an unmetered network?
- NetworkType.CONNECTED
- NetworkType.UNMETERED (Correct answer)
- NetworkType.NOT_ROAMING
- NetworkType.METERED
Correct answer: NetworkType.UNMETERED
NetworkType.UNMETERED in a Constraints builder ensures WorkManager only executes the task when the device is on a Wi-Fi or similar unmetered connection.
Question 5: What is Hilt used for in Android Jetpack?
- Layout inflation
- Dependency injection (Correct answer)
- Image loading
- Network caching
Correct answer: Dependency injection
Hilt is a Jetpack library built on Dagger that provides a standard way to perform dependency injection in Android apps with compile-time validation.
Question 6: In Jetpack Navigation, which method safely passes data between destinations with type safety?
- Bundle extras
- SharedPreferences
- Safe Args generated directions classes (Correct answer)
- Static variables
Correct answer: Safe Args generated directions classes
The Safe Args Gradle plugin generates type-safe Directions and Args classes so data is passed between Navigation destinations without manual Bundle parsing.
What is the role of a Room Entity?