AAD AAD Android Architecture & App Components 2 — Questions and Answers
Question 1: What is the purpose of the AndroidManifest.xml file in an Android project?
- To define database schemas
- To style UI components
- To declare app components, permissions, and metadata (Correct answer)
- To store user preferences
Correct answer: To declare app components, permissions, and metadata
AndroidManifest.xml declares all app components, required permissions, hardware features, and other essential app metadata to the Android system.
Question 2: Which Android component is used to share data between different applications securely?
- BroadcastReceiver
- ViewModel
- ContentProvider (Correct answer)
- JobScheduler
Correct answer: ContentProvider
A ContentProvider manages access to a central repository of data and provides a standard interface for sharing data between applications.
Question 3: What is the primary benefit of using ViewModel in Android Jetpack architecture?
- It directly manipulates the database
- It survives configuration changes like screen rotation (Correct answer)
- It replaces the need for Activities
- It handles network requests automatically
Correct answer: It survives configuration changes like screen rotation
ViewModel is designed to store and manage UI-related data in a lifecycle-conscious way, surviving configuration changes such as screen rotations.
Question 4: What is the Android back stack?
- A memory optimization technique
- A stack of Activities maintained by the system for navigation (Correct answer)
- A queue of background jobs
- A list of installed applications
Correct answer: A stack of Activities maintained by the system for navigation
The back stack is a last-in, first-out collection of Activities that the system manages so pressing the Back button navigates to the previous Activity.
Question 5: Which Activity method should you override to save UI state before the Activity is destroyed or paused?
- onStop()
- onDestroy()
- onSaveInstanceState() (Correct answer)
- onPause()
Correct answer: onSaveInstanceState()
onSaveInstanceState() is called before an Activity is destroyed so you can save UI state in a Bundle, which is restored in onCreate() or onRestoreInstanceState().
Question 6: What is a BroadcastReceiver in Android?
- A component that listens for system-wide or app-wide broadcast announcements (Correct answer)
- A component that streams audio data
- A component for managing network connections
- A background thread manager
Correct answer: A component that listens for system-wide or app-wide broadcast announcements
A BroadcastReceiver responds to broadcast messages from the Android system or other apps, such as battery-low or network-change events.
What is the purpose of the AndroidManifest.xml file in an Android project?