Test your fundamental knowledge of Android Activities, Intents, and Lifecycle stages with this beginner-friendly quiz. Sharpen your understanding of component interactions, app navigation, and core event handling using real-world scenarios.
Which component is responsible for providing a user interface screen in an Android application?
Explanation: An Activity represents a single screen with a user interface, making it the correct answer. Service is designed for background tasks and does not provide a UI. BroadcastReceiver handles system-wide broadcast announcements but does not show screens. ContentProvider manages application data and does not present any UI to users.
What is the primary purpose of using an Intent in Android development?
Explanation: Intents are mainly used to start components such as activities or services and to pass data between them. Storing user preferences relies on SharedPreferences, creating layouts uses XML or programmatic views, and sensor data is accessed through specific sensor APIs rather than Intents.
During which lifecycle method should the user interface be initialized when an Activity is created?
Explanation: The onCreate() method is called when the activity is first created, making it the ideal place to initialize the UI. onPause() and onStop() occur when the activity is losing focus or going to the background, not at creation. onDestroy() is called before the activity is destroyed, usually for cleanup.
If you want to open another activity within the same app by name, which type of Intent should you use?
Explanation: Explicit Intents specify the exact component name to start, which is perfect for switching activities within the same app. Implicit Intents do not name a target and rely on the system to find components. 'Filtered Intent' and 'Global Intent' are not standard terms in this context and do not have special meanings.
Which method is used to start a new activity, given an Intent object in Android?
Explanation: startActivity() is the correct method to launch another activity using an Intent. sendActivity(), initiateActivity(), and runActivity() are incorrect and do not exist as recognized Android methods for this purpose.
What happens by default when you press the back button while viewing a second activity that was started from the first?
Explanation: Pressing the back button typically finishes the top activity, revealing the previous one in the stack. Closing the entire app does not happen unless it was the last activity. A new instance is not created unless explicitly coded. 'No change' is incorrect since the activity stack is affected.
When a phone call arrives and your activity is partly visible, which lifecycle method is called first?
Explanation: When an activity is partly obscured, onPause() is called first, allowing the app to pause ongoing operations. onStart() is called when the activity is about to become visible, not when it becomes obscured. onResume() indicates full foreground state, while onRestart() is invoked after the activity has been stopped.
Which method do you use to attach extra data to an Intent when moving from MainActivity to DetailsActivity?
Explanation: putExtra() allows you to add simple key-value pairs to an Intent for use by the next activity. sendExtra(), addBundle(), and setDataExtra() are not correct method names for this operation and are not recognized by the Android framework.
Which method should you call to close the current activity and return to the previous one in the stack?
Explanation: Calling finish() properly ends the current activity and returns control to the previous activity. exit(), terminate(), and closeActivity() are incorrect as they are not standard methods for managing activity lifecycle and may not even exist.
If your activity might be destroyed by the system, such as during a configuration change, which method allows you to save temporary data like text input?
Explanation: onSaveInstanceState() is designed for saving transient data in situations where an activity might be destroyed and recreated. onRestoreActivity() and saveTemporaryState() do not exist, and onPauseState() is not a standard method for storing activity state.