0
0
Android Kotlinmobile~20 mins

First Android app in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
First Android App Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What will this Android app display?
Consider this simple Android app code snippet. What text will appear on the screen when the app runs?
Android Kotlin
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable

class MainActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      Greeting("Android Learner")
    }
  }
}

@Composable
fun Greeting(name: String) {
  Text(text = "Hello, $name!")
}
AHello, World!
BHello, Android Learner!
CGreeting Android Learner
DApp crashed with error
Attempts:
2 left
💡 Hint
Look at the Greeting composable and what string it uses.
lifecycle
intermediate
1:30remaining
When is onCreate() called in an Android app?
In the Android app lifecycle, when does the onCreate() method run?
AWhen the app is closed by the system
BEvery time the app goes to background
CWhen the app is first launched and the activity is created
DWhen the user presses the back button
Attempts:
2 left
💡 Hint
Think about the first step when an activity starts.
📝 Syntax
advanced
2:00remaining
What error does this Kotlin code produce?
Look at this Kotlin code snippet for an Android app. What error will it cause?
Android Kotlin
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text

class MainActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      Text(text = "Welcome")
    }
  }

  fun Text(text: String) {
    println(text)
  }
}
ACompilation error: Conflicting function names for Text
BRuntime error: NullPointerException
CNo error, app displays "Welcome" text
DSyntax error: Missing import for Text
Attempts:
2 left
💡 Hint
Check if defining a function named Text conflicts with Compose's Text composable.
navigation
advanced
2:00remaining
What happens when this navigation code runs?
Given this Android Jetpack Compose navigation snippet, what screen will the user see after clicking the button?
Android Kotlin
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.navigation.NavController

@Composable
fun FirstScreen(navController: NavController) {
  Button(onClick = { navController.navigate("second") }) {
    Text("Go to Second")
  }
}

@Composable
fun SecondScreen() {
  Text("Second Screen")
}
AThe app navigates to SecondScreen and shows "Second Screen" text
BThe app stays on FirstScreen and shows the button
CThe app crashes with navigation error
DThe app shows a blank screen
Attempts:
2 left
💡 Hint
Look at what navController.navigate("second") does.
🧠 Conceptual
expert
2:30remaining
Why use setContent in an Android Compose app?
What is the main purpose of calling setContent in an Android app using Jetpack Compose?
ATo start a background service for the app
BTo set the app's theme colors and styles globally
CTo register event listeners for user input
DTo define the UI content of the activity using composable functions
Attempts:
2 left
💡 Hint
Think about how Compose replaces XML layouts.