Challenge - 5 Problems
Passing Data Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2: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
Attempts:
2 left
💡 Hint
Check how the string extra is passed and retrieved using the same key.
✗ Incorrect
The string "Hello" is put into the Intent with key "message" and retrieved in SecondActivity with the same key, so the TextView shows "Hello".
📝 Syntax
intermediate1: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?
Attempts:
2 left
💡 Hint
Remember putExtra needs a key and a value.
✗ Incorrect
Option D correctly uses putExtra with a key "number" and an integer value 42. Option D sends a string, not integer. Option D reverses key and value. Option D misses the value.
❓ lifecycle
advanced2: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?
Attempts:
2 left
💡 Hint
Think about what happens to the Intent during activity recreation.
✗ Incorrect
The Intent that started the activity remains the same after configuration change, so extras are still available in onCreate.
🔧 Debug
advanced2: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?
Attempts:
2 left
💡 Hint
Check the exact key strings used in putExtra and getStringExtra.
✗ Incorrect
Intent extras are stored as key-value pairs. If keys don't match exactly, retrieval returns null.
🧠 Conceptual
expert3: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?
Attempts:
2 left
💡 Hint
Android recommends a specific interface for passing objects efficiently.
✗ Incorrect
Parcelable is the Android-recommended way to pass complex objects efficiently between activities via Intent extras.