Bird
Raised Fist0
Android Kotlinmobile~20 mins

Activity concept in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Activity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
What 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)
AThe screen shows SecondActivity UI, and MainActivity is paused in the background.
BThe screen remains on MainActivity, and SecondActivity runs in the background.
CThe app closes and returns to the home screen.
DBoth MainActivity and SecondActivity UI appear side by side.
Attempts:
2 left
💡 Hint
Think about what startActivity does to the current and new activity.
❓ lifecycle
intermediate
1:30remaining
Which 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?
AonStart()
BonCreate()
ConResume()
DonPause()
Attempts:
2 left
💡 Hint
Visibility means the activity is about to be seen but not yet interactive.
❓ navigation
advanced
1:30remaining
What is the effect of calling finish() inside an Activity?
If you call finish() inside an Activity, what happens next?
Android Kotlin
finish()
AThe current Activity is paused but remains visible.
BThe current Activity is destroyed and removed from the back stack, returning to the previous Activity.
CThe app closes completely.
DNothing happens until the user presses back.
Attempts:
2 left
💡 Hint
Think about what finish() means for the activity lifecycle and navigation stack.
📝 Syntax
advanced
2:00remaining
Identify 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"?
A
val intent = Intent(this, DetailActivity::class.java)
intent.addExtra("user", "Alice")
startActivity(intent)
BstartActivity(Intent(this, DetailActivity::class.java).putExtra(user = "Alice"))
C
val intent = Intent(this, DetailActivity::class.java).apply { putExtra("user", "Alice") }
startActivity(intent)
D
val intent = Intent(this, DetailActivity::class.java)
intent.put("user", "Alice")
startActivity(intent)
Attempts:
2 left
💡 Hint
Check the correct method name and syntax for adding extras to an Intent.
🔧 Debug
expert
3:00remaining
Why 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()
    }
  }
}
AThe onCreate method is missing a call to super.onStart(), causing lifecycle errors.
BToast.makeText requires applicationContext instead of this as context, causing a crash.
CsetContentView is called after findViewById, so button is null.
DThe layout activity_main.xml does not contain a view with id myButton, so findViewById returns null causing a NullPointerException.
Attempts:
2 left
💡 Hint
Check if the button view exists in the layout before accessing it.

Practice

(1/5)
1. What is the main role of an Activity in an Android app?
easy
A. It stores app data permanently.
B. It handles network requests only.
C. It manages background tasks without UI.
D. It represents a single screen with a user interface.

Solution

  1. Step 1: Understand Activity purpose

    An Activity is designed to show a screen where users interact.
  2. Step 2: Compare options

    Only It represents a single screen with a user interface. correctly describes an Activity as a UI screen.
  3. Final Answer:

    It represents a single screen with a user interface. -> Option D
  4. Quick Check:

    Activity = Screen UI [OK]
Hint: Remember: Activity = one screen in app [OK]
Common Mistakes:
  • Confusing Activity with data storage
  • Thinking Activity runs without UI
  • Mixing Activity with background services
2. Which method is used to set up the UI when an Activity starts?
easy
A. onResume()
B. onStart()
C. onCreate()
D. onPause()

Solution

  1. Step 1: Identify lifecycle methods

    onCreate() is called when the Activity is first created to set up UI.
  2. Step 2: Eliminate other methods

    onStart() and onResume() happen later; onPause() is for pausing.
  3. Final Answer:

    onCreate() -> Option C
  4. Quick Check:

    UI setup = onCreate() [OK]
Hint: UI setup always starts in onCreate() [OK]
Common Mistakes:
  • Choosing onStart() or onResume() for UI setup
  • Confusing onPause() as setup method
  • Not knowing Activity lifecycle order
3. What will happen when this Activity code runs?
class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
  }
}
medium
A. The screen shows the layout defined in activity_main.xml.
B. The app shows a blank screen.
C. Nothing happens because onCreate is empty.
D. The app crashes due to missing layout.

Solution

  1. Step 1: Analyze onCreate method

    It calls super.onCreate and sets content view to activity_main layout.
  2. Step 2: Understand setContentView effect

    This loads and displays the UI from activity_main.xml on screen.
  3. Final Answer:

    The screen shows the layout defined in activity_main.xml. -> Option A
  4. Quick Check:

    setContentView loads layout = screen shows layout [OK]
Hint: setContentView shows UI layout on screen [OK]
Common Mistakes:
  • Assuming onCreate does nothing
  • Thinking app crashes without error
  • Confusing blank screen with missing layout
4. Identify the error in this Activity code:
class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    setContentView(R.layout.activity_main)
    super.onCreate(savedInstanceState)
  }
}
medium
A. setContentView called before super.onCreate()
B. No error, code is correct
C. Missing call to super.onCreate()
D. onCreate method should not be overridden

Solution

  1. Step 1: Check order of calls in onCreate

    super.onCreate() must be called before setContentView to initialize Activity properly.
  2. Step 2: Identify mistake

    Here, setContentView is called first, which is incorrect and can cause issues.
  3. Final Answer:

    setContentView called before super.onCreate() -> Option A
  4. Quick Check:

    super.onCreate() first, then setContentView [OK]
Hint: Always call super.onCreate() before setContentView [OK]
Common Mistakes:
  • Calling setContentView before super.onCreate()
  • Forgetting to override onCreate
  • Not calling super.onCreate() at all
5. You want to start a new Activity called DetailActivity from MainActivity. Which code snippet correctly starts the new Activity?
hard
A. startActivity(DetailActivity::class.java)
B. val intent = Intent(this, DetailActivity::class.java) startActivity(intent)
C. Intent intent = new Intent(DetailActivity) startActivity(intent)
D. val intent = Intent(DetailActivity) startActivity()

Solution

  1. Step 1: Understand Intent creation

    Intent requires context (this) and target Activity class (DetailActivity::class.java).
  2. Step 2: Check startActivity usage

    startActivity(intent) correctly starts the new Activity with the Intent.
  3. Final Answer:

    val intent = Intent(this, DetailActivity::class.java) startActivity(intent) -> Option B
  4. Quick Check:

    Intent(this, TargetClass) + startActivity(intent) [OK]
Hint: Use Intent(this, TargetActivity::class.java) to start Activity [OK]
Common Mistakes:
  • Omitting context in Intent constructor
  • Calling startActivity without Intent
  • Using wrong syntax for Intent creation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard