0
0
Android Kotlinmobile~20 mins

Passing data between activities in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Passing Data Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will be displayed after passing data between activities?
Consider two activities: MainActivity sends a string "Hello" to SecondActivity using Intent extras. SecondActivity displays the received string in a TextView. What text will the TextView show?
Android Kotlin
val intent = Intent(this, SecondActivity::class.java)
intent.putExtra("message", "Hello")
startActivity(intent)

// In SecondActivity onCreate:
val message = intent.getStringExtra("message")
textView.text = message
AHello
Bnull
Cmessage
DEmpty TextView
Attempts:
2 left
💡 Hint
Check how the string extra is passed and retrieved using the same key.
📝 Syntax
intermediate
1:30remaining
Which code correctly passes an integer between activities?
You want to send an integer value 42 from MainActivity to DetailActivity. Which option correctly puts the integer into the Intent extras?
Aintent.putExtra("number")
Bintent.putExtra("number", "42")
Cintent.putExtra(42, "number")
Dintent.putExtra("number", 42)
Attempts:
2 left
💡 Hint
Remember putExtra needs a key and a value.
lifecycle
advanced
2:00remaining
What happens if you try to retrieve data from Intent in onCreate after configuration change?
If SecondActivity receives data via Intent extras and you retrieve it in onCreate, what happens when the device rotates causing a configuration change?
AThe Intent extras are lost and data becomes null.
BThe data is still available in Intent extras and can be retrieved again.
CThe activity crashes due to missing Intent data.
DThe data is saved automatically in savedInstanceState.
Attempts:
2 left
💡 Hint
Think about what happens to the Intent during activity recreation.
🔧 Debug
advanced
2:00remaining
Why does retrieving data from Intent extras return null?
You passed a string extra with key "username" from MainActivity but in SecondActivity, intent.getStringExtra("user") returns null. Why?
AThe key used to retrieve data does not match the key used to put data.
BThe Intent extras are cleared automatically after startActivity.
CThe data type must be Parcelable to pass between activities.
DYou must cast the extra to String explicitly.
Attempts:
2 left
💡 Hint
Check the exact key strings used in putExtra and getStringExtra.
🧠 Conceptual
expert
3:00remaining
What is the best way to pass a complex object between activities?
You want to pass a custom data object with multiple fields from one activity to another. Which approach is correct and efficient?
AConvert the object to JSON string and pass it as a string extra.
BStore the object in a static variable and access it from the other activity.
CMake the object implement Parcelable and pass it via Intent extras.
DSerialize the object to a file and pass the file path via Intent.
Attempts:
2 left
💡 Hint
Android recommends a specific interface for passing objects efficiently.