0
0
Android Kotlinmobile~10 mins

Activity concept in Android Kotlin - Interactive Code Practice

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

Complete the code to declare a basic Activity class in Kotlin.

Android Kotlin
class MainActivity : [1]() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
  }
}
Drag options to blanks, or click blank then click option'
AFragment
BAppCompatActivity
CService
DViewModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using Fragment or Service instead of AppCompatActivity.
Forgetting to extend any class.
2fill in blank
medium

Complete the code to set the layout resource for the Activity.

Android Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  [1](R.layout.activity_main)
}
Drag options to blanks, or click blank then click option'
AsetContentView
BfindViewById
CsetLayout
Dinflate
Attempts:
3 left
💡 Hint
Common Mistakes
Using inflate or setLayout which are not Activity methods.
Calling findViewById instead of setting the layout.
3fill in blank
hard

Fix the error in the Activity lifecycle method override.

Android Kotlin
override fun onStart() {
  super.[1]()
  // Additional code here
}
Drag options to blanks, or click blank then click option'
AonCreate
BonResume
ConStart
DonPause
Attempts:
3 left
💡 Hint
Common Mistakes
Calling super.onCreate() inside onStart.
Forgetting the super call entirely.
4fill in blank
hard

Fill both blanks to start a new Activity from the current one.

Android Kotlin
val intent = Intent(this, [1]::class.java)
[2](intent)
Drag options to blanks, or click blank then click option'
ASecondActivity
BstartActivity
CMainActivity
Dfinish
Attempts:
3 left
💡 Hint
Common Mistakes
Using finish() instead of startActivity().
Using the wrong Activity class in the Intent.
5fill in blank
hard

Fill all three blanks to pass data to another Activity using Intent extras.

Android Kotlin
val intent = Intent(this, [1]::class.java)
intent.[2]("username", "Alice")
[3](intent)
Drag options to blanks, or click blank then click option'
ADetailActivity
BputExtra
CstartActivity
DgetExtra
Attempts:
3 left
💡 Hint
Common Mistakes
Using getExtra instead of putExtra.
Forgetting to call startActivity.
Passing wrong Activity class.