Android Activities, Intents, and Lifecycle Essentials Quiz Quiz

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.

  1. Identifying an Activity

    Which component is responsible for providing a user interface screen in an Android application?

    1. Service
    2. Activity
    3. ContentProvider
    4. BroadcastReceiver

    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.

  2. Intent Purpose

    What is the primary purpose of using an Intent in Android development?

    1. To start another activity or service
    2. To store user preferences
    3. To access sensor data
    4. To create layouts

    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.

  3. Lifecycle: Creation Phase

    During which lifecycle method should the user interface be initialized when an Activity is created?

    1. onDestroy()
    2. onPause()
    3. onCreate()
    4. onStop()

    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.

  4. Explicit vs Implicit Intents

    If you want to open another activity within the same app by name, which type of Intent should you use?

    1. Global Intent
    2. Implicit Intent
    3. Filtered Intent
    4. Explicit Intent

    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.

  5. Launching an Activity

    Which method is used to start a new activity, given an Intent object in Android?

    1. sendActivity()
    2. runActivity()
    3. startActivity()
    4. initiateActivity()

    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.

  6. Activity Back Stack

    What happens by default when you press the back button while viewing a second activity that was started from the first?

    1. A new instance of the first activity is launched
    2. The entire app closes
    3. No change occurs
    4. The second activity finishes and the first activity resumes

    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.

  7. Lifecycle: Pausing

    When a phone call arrives and your activity is partly visible, which lifecycle method is called first?

    1. onStart()
    2. onRestart()
    3. onPause()
    4. onResume()

    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.

  8. Passing Data Between Activities

    Which method do you use to attach extra data to an Intent when moving from MainActivity to DetailsActivity?

    1. setDataExtra()
    2. sendExtra()
    3. addBundle()
    4. putExtra()

    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.

  9. Finishing an Activity

    Which method should you call to close the current activity and return to the previous one in the stack?

    1. terminate()
    2. closeActivity()
    3. finish()
    4. exit()

    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.

  10. Saving State

    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?

    1. saveTemporaryState()
    2. onSaveInstanceState()
    3. onPauseState()
    4. onRestoreActivity()

    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.