0
0
Android Kotlinmobile~10 mins

Why understanding lifecycle prevents bugs in Android Kotlin - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to override the onCreate method in an Android Activity.

Android Kotlin
override fun [1](savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
}
Drag options to blanks, or click blank then click option'
AonResume
BonStart
ConCreate
DonPause
Attempts:
3 left
💡 Hint
Common Mistakes
Using onStart instead of onCreate
Forgetting to call super.onCreate
2fill in blank
medium

Complete the code to save data when the activity is about to be destroyed.

Android Kotlin
override fun [1](outState: Bundle) {
    super.onSaveInstanceState(outState)
    outState.putString("key", "value")
}
Drag options to blanks, or click blank then click option'
AonDestroy
BonSaveInstanceState
ConStop
DonPause
Attempts:
3 left
💡 Hint
Common Mistakes
Saving data in onDestroy which is not guaranteed to be called
Not calling super.onSaveInstanceState
3fill in blank
hard

Fix the error in the lifecycle method to properly release resources.

Android Kotlin
override fun [1]() {
    super.onDestroy()
    mediaPlayer.release()
}
Drag options to blanks, or click blank then click option'
AonResume
BonPause
ConStop
DonDestroy
Attempts:
3 left
💡 Hint
Common Mistakes
Releasing resources in onPause which may be called multiple times
Not calling super.onDestroy
4fill in blank
hard

Fill both blanks to correctly handle UI updates when the activity becomes visible.

Android Kotlin
override fun [1]() {
    super.[2]()
    updateUI()
}
Drag options to blanks, or click blank then click option'
AonStart
BonResume
ConPause
DonStop
Attempts:
3 left
💡 Hint
Common Mistakes
Using onStart instead of onResume for UI updates
Forgetting to call super method
5fill in blank
hard

Fill all three blanks to correctly manage a media player across lifecycle events.

Android Kotlin
override fun [1]() {
    super.[1]()
    mediaPlayer.start()
}
override fun [2]() {
    super.[2]()
    mediaPlayer.pause()
}
override fun [3]() {
    super.[3]()
    mediaPlayer.release()
}
Drag options to blanks, or click blank then click option'
AonStart
BonPause
ConDestroy
DonStop
Attempts:
3 left
💡 Hint
Common Mistakes
Starting media in onResume but releasing in onStop
Not releasing media player in onDestroy