0
0
Android Kotlinmobile~20 mins

Intent for activity navigation in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Intent Navigator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when this Intent code runs?
Consider this Kotlin code inside an Android activity. What will the user see after clicking the button?
Android Kotlin
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)
AThe app closes immediately.
BThe app opens SecondActivity screen.
CThe app shows an error message.
DNothing happens; the screen stays the same.
Attempts:
2 left
💡 Hint
Intent is used to start a new screen (activity).
📝 Syntax
intermediate
2:00remaining
Which option correctly creates an Intent to start DetailActivity?
Choose the correct Kotlin code snippet to start DetailActivity from the current activity.
A
val intent = Intent(this, DetailActivity::class.java)
startActivity(intent)
B
val intent = Intent(DetailActivity::class.java, this)
startActivity(intent)
C
val intent = Intent(this, "DetailActivity")
startActivity(intent)
D
val intent = Intent(this)
startActivity(DetailActivity::class.java)
Attempts:
2 left
💡 Hint
Intent constructor needs context and target activity class.
lifecycle
advanced
2:00remaining
What happens to the current activity after startActivity(intent)?
After calling startActivity(intent) to open a new activity, what is the state of the current activity?
AIt is restarted.
BIt is destroyed immediately.
CIt is paused and stopped but remains in the back stack.
DIt becomes invisible and removed from memory.
Attempts:
2 left
💡 Hint
Think about Android activity lifecycle when switching screens.
🔧 Debug
advanced
2:00remaining
Why does this Intent code cause a crash?
Given this code snippet, why does the app crash when startActivity is called? val intent = Intent(this, SecondActivity::class.java) startActivity(intent)
Android Kotlin
class FirstActivity : AppCompatActivity() {
  fun openSecond() {
    val intent = Intent(this, SecondActivity::class.java)
    startActivity(intent)
  }
}

class SecondActivity : AppCompatActivity() {}
ASecondActivity is not declared in AndroidManifest.xml.
BIntent constructor parameters are reversed.
CstartActivity is called outside an activity context.
DSecondActivity class is missing a constructor.
Attempts:
2 left
💡 Hint
Android requires all activities to be registered in the manifest.
🧠 Conceptual
expert
2:00remaining
What is the purpose of Intent flags in activity navigation?
Why would a developer add flags like FLAG_ACTIVITY_CLEAR_TOP to an Intent before starting an activity?
ATo pass data between activities securely.
BTo change the theme of the new activity dynamically.
CTo delay the start of the activity until a condition is met.
DTo control how activities are launched and manage the back stack behavior.
Attempts:
2 left
💡 Hint
Flags affect how Android handles activity instances and navigation history.