Hint: Use this and TargetActivity::class.java in Intent [OK]
Common Mistakes:
Swapping parameters order
Omitting ::class.java
Using activity instance instead of class
3. What will happen when the following code runs inside an activity?
val intent = Intent(this, DetailActivity::class.java)
startActivity(intent)
medium
A. The app will crash due to missing permissions
B. The current activity will close and DetailActivity will open
C. Nothing will happen because startActivity is missing parameters
D. DetailActivity will open on top of the current activity
Solution
Step 1: Analyze Intent creation
The Intent is correctly created to open DetailActivity from the current context.
Step 2: Understand startActivity behavior
Calling startActivity launches the new activity on top without closing the current one.
Final Answer:
DetailActivity will open on top of the current activity -> Option D
Quick Check:
startActivity(intent) = Opens new screen on top [OK]
Hint: startActivity opens new screen on top [OK]
Common Mistakes:
Thinking startActivity closes current activity
Assuming permissions needed for navigation
Believing startActivity requires extra parameters
4. Identify the error in this code snippet that tries to start ProfileActivity:
val intent = Intent(ProfileActivity::class.java, this)
startActivity(intent)
medium
A. The parameters in Intent are reversed
B. startActivity is missing parentheses
C. ProfileActivity should be an instance, not a class
D. Intent requires a string action, not classes
Solution
Step 1: Check Intent constructor parameter order
The Intent constructor expects the current context first, then the target activity class.
Step 2: Identify parameter reversal
Here, the target activity class is given first, then the context, which is incorrect.
Final Answer:
The parameters in Intent are reversed -> Option A
Quick Check:
Intent(this, TargetActivity::class.java) = Correct order [OK]
Hint: Context first, target class second in Intent [OK]
Common Mistakes:
Swapping context and target activity
Forgetting ::class.java
Using activity instance instead of context
5. You want to open SettingsActivity and close the current activity so the user cannot return by pressing back. Which code snippet achieves this?
hard
A. val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
B. val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
finish()
C. val intent = Intent(this, SettingsActivity::class.java)
finish()
startActivity(intent)
D. val intent = Intent(this, SettingsActivity::class.java)
startActivityForResult(intent, 1)
Solution
Step 1: Understand startActivity and finish
startActivity opens the new activity; finish closes the current one.
Step 2: Order matters
Calling finish() after startActivity ensures the new screen opens before current closes.
Step 3: Check options
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
finish() correctly calls startActivity then finish to prevent back navigation.
Final Answer:
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
finish() -> Option B
Quick Check:
startActivity + finish = Open new and close current [OK]
Hint: Call finish() after startActivity to close current [OK]
Common Mistakes:
Calling finish() before startActivity
Not calling finish() at all
Using startActivityForResult unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.