Intent extras are used to pass small amounts of data between activities in an Android app. They act like a bundle of key-value pairs attached to the Intent.
Click to reveal answer
beginner
How do you add data to an Intent before starting a new activity?
Use the putExtra() method on the Intent object, providing a key and a value. For example: intent.putExtra("username", "Alice")
Click to reveal answer
beginner
How does the receiving activity retrieve data passed via Intent extras?
In the receiving activity, call intent.getStringExtra("key") or the appropriate getExtra method inside onCreate() to get the data sent from the previous activity.
Click to reveal answer
intermediate
What happens if you try to get an extra with a key that was not sent?
The getExtra method returns null (or a default value for primitives). Always check for null to avoid crashes.
Click to reveal answer
intermediate
Can you pass complex objects between activities using Intent extras?
Yes, but the objects must implement Parcelable or Serializable interfaces to be passed via Intent extras.
Click to reveal answer
Which method is used to add data to an Intent before starting a new activity?
AputExtra()
BgetExtra()
CstartActivity()
DsetContentView()
✗ Incorrect
putExtra() adds key-value data to the Intent to pass to the next activity.
How do you retrieve a String extra named "user" in the receiving activity?
AstartActivity(intent)
Bintent.getStringExtra("user")
CgetIntent().putExtra("user")
Dintent.getExtra("user")
✗ Incorrect
Use intent.getStringExtra("user") to get the String value passed with key "user".
What must a custom object implement to be passed via Intent extras?
ARunnable
BActivity
CView
DParcelable or Serializable
✗ Incorrect
Custom objects must implement Parcelable or Serializable to be passed between activities.
If you try to get an extra that was not sent, what will happen?
AStarts a new activity
BApp crashes immediately
CReturns null or default value
DThrows a compile error
✗ Incorrect
Getting a missing extra returns null or a default value; it does not crash but you should check for null.
Which Android component is responsible for starting a new screen (activity)?
AIntent
BView
CService
DBroadcastReceiver
✗ Incorrect
Intent is used to start new activities and can carry data between them.
Explain how to pass a username string from one activity to another in Android using Kotlin.
Think about how you attach data to the Intent and how the next screen reads it.
You got /4 concepts.
Describe how you would pass a custom data object between activities and what requirements that object must meet.
Consider Android's rules for passing complex data.
You got /3 concepts.
Practice
(1/5)
1. What is the primary method to send data from one activity to another in Android Kotlin?
easy
A. Use an Intent with putExtra() to attach data.
B. Use a global variable to share data.
C. Call the other activity's method directly.
D. Use a database to pass data instantly.
Solution
Step 1: Understand Intent usage
Intent is the standard way to start a new activity and can carry data with putExtra().
Step 2: Recognize data passing method
putExtra() attaches key-value pairs to the Intent for the next activity to retrieve.
Final Answer:
Use an Intent with putExtra() to attach data. -> Option A
Quick Check:
Intent + putExtra() = Data passing [OK]
Hint: Remember: Intent carries data with putExtra() [OK]
Common Mistakes:
Trying to call methods of another activity directly
Using global variables which is not recommended
Assuming database is needed for simple data passing
2. Which of the following is the correct syntax to add a String extra named "username" to an Intent in Kotlin?
easy
A. intent.setExtra("username", username)
B. intent.addExtra("username" to username)
C. intent.putExtra("username", username)
D. intent.putData("username", username)
Solution
Step 1: Recall Intent method for extras
putExtra() is the correct method to add data to an Intent.
Step 2: Check syntax correctness
putExtra() takes a key and a value as parameters, matching intent.putExtra("username", username).