Bird
Raised Fist0
Android Kotlinmobile~20 mins

Activity lifecycle methods (onCreate, onStart, onResume, onPause, onStop, onDestroy) in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Lifecycle Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
Which lifecycle method is called when the activity becomes visible to the user?
An Android activity goes through several lifecycle stages. When the activity is about to become visible but not yet interactive, which method is called?
AonStart()
BonResume()
ConPause()
DonCreate()
Attempts:
2 left
💡 Hint
Think about the method that makes the activity visible but not yet ready for user interaction.
❓ ui_behavior
intermediate
2:00remaining
What lifecycle method is called when the activity is no longer visible?
When an activity moves out of the screen and is no longer visible to the user, which lifecycle method is called?
AonStop()
BonPause()
ConDestroy()
DonResume()
Attempts:
2 left
💡 Hint
This method is called after the activity is no longer visible but before it is destroyed.
❓ lifecycle
advanced
2:00remaining
What is the correct order of lifecycle method calls when an activity is launched and then the user presses the home button?
Consider the sequence of lifecycle methods called when an activity starts and then the user presses the home button to send the app to the background. Which option shows the correct order?
AonCreate() → onStart() → onPause() → onResume() → onStop()
BonCreate() → onResume() → onStart() → onPause() → onStop()
ConStart() → onCreate() → onResume() → onPause() → onStop()
DonCreate() → onStart() → onResume() → onPause() → onStop()
Attempts:
2 left
💡 Hint
Remember the lifecycle starts with onCreate, then onStart, then onResume when the activity is interactive.
🔧 Debug
advanced
2:00remaining
What error occurs if you try to update UI elements in onStop()?
In Android, if you try to update UI elements (like TextView) inside the onStop() method, what kind of problem or error will most likely happen?
ANo error, UI updates work normally
BIllegalStateException because UI is not visible
CUI updates are ignored silently without error
DNullPointerException because views are destroyed
Attempts:
2 left
💡 Hint
Think about whether the UI is visible and interactive during onStop().
🧠 Conceptual
expert
2:00remaining
Which lifecycle method is guaranteed to be called before the activity is destroyed?
When an Android activity is finishing or being destroyed by the system, which lifecycle method is always called before the activity is destroyed?
AonStop()
BonPause()
ConDestroy()
DonSaveInstanceState()
Attempts:
2 left
💡 Hint
Consider the lifecycle method that is called first when the activity is about to go away.

Practice

(1/5)
1. Which lifecycle method is called first when an Android activity is launched?
onCreate(), onStart(), onResume(), or onPause()?
easy
A. onStart()
B. onResume()
C. onCreate()
D. onPause()

Solution

  1. Step 1: Understand activity launch sequence

    When an activity starts, onCreate() is the first method called to set up the UI and initialize components.
  2. Step 2: Confirm order of lifecycle methods

    After onCreate(), onStart() and onResume() follow, but they are not first.
  3. Final Answer:

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

    First lifecycle method = onCreate() [OK]
Hint: Remember: onCreate() is always first when activity starts [OK]
Common Mistakes:
  • Confusing onStart() as the first method
  • Thinking onResume() is called before onCreate()
  • Assuming onPause() is called on launch
2. Which of the following is the correct Kotlin syntax to override the onPause() method in an Android activity?
easy
A. override fun onPause() { pause.super() }
B. fun onPause() { super.onPause() }
C. override onPause() { super.onPause() }
D. override fun onPause() { super.onPause() }

Solution

  1. Step 1: Check Kotlin override syntax

    In Kotlin, to override a method, use override fun methodName() and call super.methodName() inside.
  2. Step 2: Validate each option

    override fun onPause() { super.onPause() } correctly uses override fun onPause() and calls super.onPause(). Others miss override keyword, have wrong syntax, or wrong super call.
  3. Final Answer:

    override fun onPause() { super.onPause() } -> Option D
  4. Quick Check:

    Correct override syntax = override fun onPause() { super.onPause() } [OK]
Hint: Always use 'override fun method()' and call 'super.method()' inside [OK]
Common Mistakes:
  • Omitting the override keyword
  • Calling super incorrectly
  • Wrong function declaration syntax
3. Consider this Kotlin code snippet inside an activity:
override fun onPause() {
    super.onPause()
    println("Paused")
}
override fun onStop() {
    super.onStop()
    println("Stopped")
}

What will be printed if the user presses the home button while the activity is visible?
medium
A. Stopped Paused
B. Paused Stopped
C. Paused
D. Stopped

Solution

  1. Step 1: Understand lifecycle on home press

    Pressing home triggers onPause() first, then onStop() as activity goes to background.
  2. Step 2: Check print order

    Since onPause() runs before onStop(), "Paused" prints first, then "Stopped".
  3. Final Answer:

    Paused Stopped -> Option B
  4. Quick Check:

    onPause() then onStop() prints = Paused, Stopped [OK]
Hint: onPause() always runs before onStop() when leaving activity [OK]
Common Mistakes:
  • Assuming onStop() runs before onPause()
  • Thinking only one method runs on home press
  • Confusing print order
4. This code snippet is intended to save data when the activity is paused:
override fun onPause() {
    saveData()
}

What is the main problem with this code?
medium
A. Missing call to super.onPause()
B. saveData() should be called in onStop() instead
C. onPause() cannot be overridden
D. saveData() must be asynchronous

Solution

  1. Step 1: Check lifecycle method override rules

    When overriding lifecycle methods, always call super.method() to keep system stable.
  2. Step 2: Identify missing super call

    The code lacks super.onPause(), which can cause unexpected behavior.
  3. Final Answer:

    Missing call to super.onPause() -> Option A
  4. Quick Check:

    Always call super in lifecycle overrides [OK]
Hint: Never forget super.onPause() when overriding onPause() [OK]
Common Mistakes:
  • Forgetting to call super method
  • Thinking onPause() can't be overridden
  • Assuming saveData() timing is wrong
5. You want to release a camera resource when the activity is no longer visible to save battery. Which lifecycle method is the best place to release the camera?
A) onDestroy()
B) onStop()
C) onPause()
D) onResume()
hard
A. onPause()
B. onStop()
C. onDestroy()
D. onResume()

Solution

  1. Step 1: Understand visibility and resource management

    When activity is partially or fully hidden, onPause() is called first, signaling to release resources like camera to save battery.
  2. Step 2: Compare lifecycle methods for releasing resources

    onStop() is later, but releasing in onPause() ensures resources are freed as soon as activity is not in foreground. onDestroy() may never be called if system kills process. onResume() is for acquiring resources.
  3. Final Answer:

    onPause() -> Option A
  4. Quick Check:

    Release resources in onPause() to save battery [OK]
Hint: Release heavy resources in onPause(), reacquire in onResume() [OK]
Common Mistakes:
  • Waiting until onStop() or onDestroy() to release resources
  • Releasing resources in onResume() by mistake
  • Not releasing resources early enough
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