Bird
Raised Fist0
Android Kotlinmobile~5 mins

First Android app in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is the entry point of an Android app?
The entry point is the MainActivity class, which extends AppCompatActivity and contains the onCreate() method.
Click to reveal answer
beginner
What does the setContentView() method do in an Android activity?
It sets the layout resource file that defines the UI for the activity, making the UI visible on the screen.
Click to reveal answer
beginner
Which file defines the UI layout for the first Android app?
The UI layout is defined in an XML file located in res/layout/activity_main.xml.
Click to reveal answer
intermediate
What is the purpose of the AndroidManifest.xml file?
It declares app components, permissions, and metadata. It tells Android which activity to start first.
Click to reveal answer
beginner
How do you display a simple text message on the screen in your first Android app?
By adding a TextView element in the layout XML file with the desired text.
Click to reveal answer
Which method is called when an Android activity starts?
AonCreate()
BonStart()
ConResume()
DonPause()
Where do you define the UI layout for an Android activity?
AIn Kotlin code only
BIn res/layout XML files
CIn AndroidManifest.xml
DIn build.gradle
What does setContentView(R.layout.activity_main) do?
AStarts a new activity
BDeclares app permissions
CSets the UI layout for the current activity
DStops the app
Which file tells Android which activity to launch first?
AAndroidManifest.xml
BMainActivity.kt
Cactivity_main.xml
Dstrings.xml
What is the purpose of the TextView in Android?
ATo display images
BTo play audio
CTo handle user input
DTo display text
Explain the steps to create and display a simple 'Hello World' message in your first Android app.
Think about the activity lifecycle and UI layout files.
You got /4 concepts.
    Describe the role of AndroidManifest.xml in launching your first Android app.
    It acts like a map for Android to know what to start.
    You got /3 concepts.

      Practice

      (1/5)
      1. What is the role of the MainActivity class in a simple Android app?
      easy
      A. It controls what the user sees by loading the layout and handling interactions.
      B. It stores user data permanently on the device.
      C. It manages network connections for the app.
      D. It compiles the app code into machine language.

      Solution

      1. Step 1: Understand MainActivity's purpose

        MainActivity is the entry point of the app that sets the screen content.
      2. Step 2: Identify its function in UI

        It loads the layout file which defines what the user sees and handles user actions.
      3. Final Answer:

        It controls what the user sees by loading the layout and handling interactions. -> Option A
      4. Quick Check:

        MainActivity controls UI = A [OK]
      Hint: MainActivity sets the screen content and user interaction [OK]
      Common Mistakes:
      • Confusing MainActivity with data storage classes
      • Thinking MainActivity handles network tasks
      • Believing MainActivity compiles code
      2. Which of the following is the correct way to set the content view in MainActivity using Kotlin?
      easy
      A. setContentView(R.id.activity_main)
      B. setContentView(R.layout.activity_main)
      C. setContentView(activity_main.xml)
      D. setContentView("activity_main")

      Solution

      1. Step 1: Recall setContentView syntax

        In Kotlin, setContentView expects a layout resource ID, accessed as R.layout.filename.
      2. Step 2: Match correct resource reference

        R.layout.activity_main correctly points to the layout XML file named activity_main.xml.
      3. Final Answer:

        setContentView(R.layout.activity_main) -> Option B
      4. Quick Check:

        Layout resource ID = R.layout.filename [OK]
      Hint: Use R.layout.filename to reference layout files [OK]
      Common Mistakes:
      • Using string names instead of resource IDs
      • Confusing layout and id resources
      • Including file extensions in code
      3. Given this Kotlin code in MainActivity:
      override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
      }
      What will the user see when the app runs?
      medium
      A. A blank white screen with no text
      B. An error message because onCreate is missing a return type
      C. Nothing, the app will crash immediately
      D. The layout defined in activity_main.xml displayed on screen

      Solution

      1. Step 1: Understand onCreate behavior

        onCreate is called when the app starts and sets the UI with setContentView.
      2. Step 2: Effect of setContentView

        It loads the layout file activity_main.xml, so the user sees that layout on screen.
      3. Final Answer:

        The layout defined in activity_main.xml displayed on screen -> Option D
      4. Quick Check:

        setContentView loads layout = C [OK]
      Hint: onCreate sets UI with setContentView(layout) [OK]
      Common Mistakes:
      • Thinking onCreate needs a return type
      • Assuming no UI appears without extra code
      • Confusing layout with id resources
      4. What is wrong with this MainActivity code snippet?
      override fun onCreate(savedInstanceState: Bundle?) {
        setContentView(R.layout.activity_main)
        super.onCreate(savedInstanceState)
      }
      medium
      A. setContentView should be called outside onCreate
      B. savedInstanceState should be nullable (Bundle?)
      C. super.onCreate(savedInstanceState) must be called before setContentView
      D. onCreate must return a value

      Solution

      1. Step 1: Check onCreate call order

        super.onCreate must be called first to properly initialize the activity.
      2. Step 2: Identify correct order

        Calling setContentView before super.onCreate causes errors or unexpected behavior.
      3. Final Answer:

        super.onCreate(savedInstanceState) must be called before setContentView -> Option C
      4. Quick Check:

        super.onCreate first = B [OK]
      Hint: Always call super.onCreate first inside onCreate [OK]
      Common Mistakes:
      • Calling setContentView before super.onCreate
      • Using non-nullable Bundle parameter
      • Expecting onCreate to return a value
      5. You want your first Android app to show a greeting message centered on a white background. Which layout XML snippet achieves this?
      hard
      A.
      B.
      C.
      D.

      Solution

      1. Step 1: Check layout size and background

        uses match_parent for width and height and sets background to white (#FFFFFF).
      2. Step 2: Verify text centering

        android:gravity=\"center\" centers the TextView inside the LinearLayout.
      3. Final Answer:

        -> Option A
      4. Quick Check:

        Center gravity + white background = A [OK]
      Hint: Use LinearLayout with gravity=center and background=#FFFFFF [OK]
      Common Mistakes:
      • Using wrap_content for parent layout size
      • Missing gravity=center for centering
      • Not setting background color
      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