Challenge - 5 Problems
Activity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediateWhat happens when an Activity is launched?
Consider an Android app where MainActivity starts SecondActivity. What is the visible result after calling startActivity(Intent(this, SecondActivity::class.java))?
Android Kotlin
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)Attempts:
2 left
💡 Hint
Think about what startActivity does to the current and new activity.
✗ Incorrect
When startActivity is called, the new activity (SecondActivity) is brought to the front and shown. The previous activity (MainActivity) is paused but still in memory.
❓ lifecycle
intermediateWhich lifecycle method is called when an Activity becomes visible?
In Android, when an Activity moves from not visible to visible on screen, which lifecycle method is called?
Attempts:
2 left
💡 Hint
Visibility means the activity is about to be seen but not yet interactive.
✗ Incorrect
onStart() is called when the activity becomes visible but before it gains focus. onResume() is called after onStart() when the activity is ready for user interaction.
advanced
What is the effect of calling finish() inside an Activity?
If you call finish() inside an Activity, what happens next?
Android Kotlin
finish()
Attempts:
2 left
💡 Hint
Think about what finish() means for the activity lifecycle and navigation stack.
✗ Incorrect
Calling finish() ends the current activity and removes it from the back stack, so the previous activity is shown.
📝 Syntax
advancedIdentify the correct way to start an Activity with data in Kotlin
Which code snippet correctly starts DetailActivity passing a String extra with key "user" and value "Alice"?
Attempts:
2 left
💡 Hint
Check the correct method name and syntax for adding extras to an Intent.
✗ Incorrect
putExtra(key, value) is the correct method to add data to an Intent. The other options use invalid method names or syntax.
🔧 Debug
expertWhy does this Activity crash on launch?
Given this Activity code, why does the app crash immediately when launched?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById
Android Kotlin
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val button = findViewById<Button>(R.id.myButton) button.setOnClickListener { Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show() } } }
Attempts:
2 left
💡 Hint
Check if the button view exists in the layout before accessing it.
✗ Incorrect
If findViewById returns null because the view id is missing, calling setOnClickListener on null causes a crash (NullPointerException).
