Android Development Android Development 5 — Questions and Answers
Question 1: Your app targets API 33+ and needs to show notifications. What must you do first?
- Request the POST_NOTIFICATIONS runtime permission (Correct answer)
- Declare a foreground service
- Enable notifications in Gradle
- Nothing; notifications are always allowed
Correct answer: Request the POST_NOTIFICATIONS runtime permission
Android 13 (API 33) introduced the POST_NOTIFICATIONS runtime permission, which users must grant before notifications appear.
Question 2: What is the main advantage of using ConstraintLayout over deeply nested LinearLayouts?
- Automatic dark theme support
- Smaller APK size
- Built-in data binding
- A flatter view hierarchy, which improves layout measurement performance (Correct answer)
Correct answer: A flatter view hierarchy, which improves layout measurement performance
ConstraintLayout positions views with constraints in a single flat layer, avoiding costly nested measure passes.
Question 3: A QA engineer wants to test an Activity's UI interactions automatically on a device. Which framework is designed for this?
- Mockito
- Logcat
- Espresso (Correct answer)
- JUnit running on the JVM
Correct answer: Espresso
Espresso drives and asserts on real UI components in instrumented tests running on a device or emulator.
Question 4: What happens to an app's process when the system is low on memory and the app is in the background?
- The app is uninstalled
- The system may kill the process, and saved instance state helps restore the UI later (Correct answer)
- The process is never killed while it holds a ViewModel
- The process is frozen permanently
Correct answer: The system may kill the process, and saved instance state helps restore the UI later
Android reclaims memory by killing background processes, so apps must save state to restore correctly on return.
Question 5: In Kotlin, what does a 'sealed class' provide when modeling UI states like Loading, Success, and Error?
- Automatic JSON serialization of each state
- Persistence of state across sessions
- A restricted class hierarchy enabling exhaustive when-expression handling (Correct answer)
- Thread-safe state mutation
Correct answer: A restricted class hierarchy enabling exhaustive when-expression handling
Sealed classes limit subclasses to a known set, so a when expression can be checked for exhaustiveness at compile time.
Question 6: Which statement about App Bundles (.aab) versus APKs is correct?
- Bundles remove the need for code signing
- APKs always download faster than bundles
- An .aab can be installed directly on any device without processing
- Play generates optimized per-device APKs from the bundle, reducing download size (Correct answer)
Correct answer: Play generates optimized per-device APKs from the bundle, reducing download size
The Android App Bundle lets Google Play deliver split APKs containing only the resources and code each device needs.
Question 7: What is the purpose of ProGuard/R8 in a release build?
- Compiling Kotlin to Java
- Generating unit test stubs
- Shrinking, obfuscating, and optimizing code to reduce size and hinder reverse engineering (Correct answer)
- Signing the APK for the Play Store
Correct answer: Shrinking, obfuscating, and optimizing code to reduce size and hinder reverse engineering
R8 removes unused code, renames symbols, and optimizes bytecode in release builds.
Your app targets API 33+ and needs to show notifications.
What must you do first?