Complete the code to override the onCreate method in an Android Activity.
override fun [1](savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}The onCreate method is called when the activity is first created. Overriding it allows you to set up your UI and initialize components.
Complete the code to save data when the activity is about to be destroyed.
override fun [1](outState: Bundle) { super.onSaveInstanceState(outState) outState.putString("key", "value") }
The onSaveInstanceState method is called before the activity may be destroyed. It allows saving UI state to restore later.
Fix the error in the lifecycle method to properly release resources.
override fun [1]() {
super.onDestroy()
mediaPlayer.release()
}The onDestroy method is the right place to release resources like media players to avoid memory leaks.
Fill both blanks to correctly handle UI updates when the activity becomes visible.
override fun [1]() { super.[2]() updateUI() }
The onResume method is called when the activity is ready to interact with the user. Updating UI here ensures the latest data is shown.
Fill all three blanks to correctly manage a media player across lifecycle events.
override fun [1]() { super.[1]() mediaPlayer.start() } override fun [2]() { super.[2]() mediaPlayer.pause() } override fun [3]() { super.[3]() mediaPlayer.release() }
onStart starts the media player when the activity becomes visible. onPause pauses it when the activity loses focus. onDestroy releases resources to prevent leaks.