Bird
Raised Fist0
Android Kotlinmobile~5 mins

Activity concept in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is an Activity in Android?
An Activity is a single screen in an Android app where the user interacts. It controls the UI and handles user actions.
Click to reveal answer
beginner
Which method is called when an Activity is first created?
The onCreate() method is called when the Activity is first created. It is where you set up the UI and initialize components.
Click to reveal answer
intermediate
Name two lifecycle methods called when an Activity becomes visible and when it goes to the background.
onStart() is called when the Activity becomes visible. onStop() is called when the Activity is no longer visible (goes to background).
Click to reveal answer
beginner
How do you start a new Activity from the current Activity?
You create an Intent specifying the new Activity class and call startActivity(intent) to open it.
Click to reveal answer
intermediate
What is the purpose of the onPause() method in an Activity?
onPause() is called when the Activity is partially obscured or about to go into the background. Use it to pause animations or save data.
Click to reveal answer
Which method is NOT part of the Activity lifecycle?
AonClick()
BonStart()
ConCreate()
DonDestroy()
What does the onResume() method indicate?
AActivity is visible and interacting with the user
BActivity is being created
CActivity is stopped
DActivity is destroyed
How do you open a new Activity named DetailActivity?
AopenActivity(DetailActivity)
BstartActivity(Intent(this, DetailActivity::class.java))
Claunch(DetailActivity)
Dnew Activity(DetailActivity)
Which lifecycle method should you use to save user data before the Activity is stopped?
AonCreate()
BonStart()
ConPause()
DonResume()
What happens when you call finish() inside an Activity?
ANothing happens
BThe Activity restarts
CThe Activity pauses
DThe Activity closes and is removed from the stack
Explain the Android Activity lifecycle and why it is important.
Think about what happens when the user opens, uses, and leaves an Activity.
You got /8 concepts.
    Describe how to navigate from one Activity to another in Android.
    Consider how you tell Android to show a new screen.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main role of an Activity in an Android app?
      easy
      A. It stores app data permanently.
      B. It handles network requests only.
      C. It manages background tasks without UI.
      D. It represents a single screen with a user interface.

      Solution

      1. Step 1: Understand Activity purpose

        An Activity is designed to show a screen where users interact.
      2. Step 2: Compare options

        Only It represents a single screen with a user interface. correctly describes an Activity as a UI screen.
      3. Final Answer:

        It represents a single screen with a user interface. -> Option D
      4. Quick Check:

        Activity = Screen UI [OK]
      Hint: Remember: Activity = one screen in app [OK]
      Common Mistakes:
      • Confusing Activity with data storage
      • Thinking Activity runs without UI
      • Mixing Activity with background services
      2. Which method is used to set up the UI when an Activity starts?
      easy
      A. onResume()
      B. onStart()
      C. onCreate()
      D. onPause()

      Solution

      1. Step 1: Identify lifecycle methods

        onCreate() is called when the Activity is first created to set up UI.
      2. Step 2: Eliminate other methods

        onStart() and onResume() happen later; onPause() is for pausing.
      3. Final Answer:

        onCreate() -> Option C
      4. Quick Check:

        UI setup = onCreate() [OK]
      Hint: UI setup always starts in onCreate() [OK]
      Common Mistakes:
      • Choosing onStart() or onResume() for UI setup
      • Confusing onPause() as setup method
      • Not knowing Activity lifecycle order
      3. What will happen when this Activity code runs?
      class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
        }
      }
      medium
      A. The screen shows the layout defined in activity_main.xml.
      B. The app shows a blank screen.
      C. Nothing happens because onCreate is empty.
      D. The app crashes due to missing layout.

      Solution

      1. Step 1: Analyze onCreate method

        It calls super.onCreate and sets content view to activity_main layout.
      2. Step 2: Understand setContentView effect

        This loads and displays the UI from activity_main.xml on screen.
      3. Final Answer:

        The screen shows the layout defined in activity_main.xml. -> Option A
      4. Quick Check:

        setContentView loads layout = screen shows layout [OK]
      Hint: setContentView shows UI layout on screen [OK]
      Common Mistakes:
      • Assuming onCreate does nothing
      • Thinking app crashes without error
      • Confusing blank screen with missing layout
      4. Identify the error in this Activity code:
      class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
          setContentView(R.layout.activity_main)
          super.onCreate(savedInstanceState)
        }
      }
      medium
      A. setContentView called before super.onCreate()
      B. No error, code is correct
      C. Missing call to super.onCreate()
      D. onCreate method should not be overridden

      Solution

      1. Step 1: Check order of calls in onCreate

        super.onCreate() must be called before setContentView to initialize Activity properly.
      2. Step 2: Identify mistake

        Here, setContentView is called first, which is incorrect and can cause issues.
      3. Final Answer:

        setContentView called before super.onCreate() -> Option A
      4. Quick Check:

        super.onCreate() first, then setContentView [OK]
      Hint: Always call super.onCreate() before setContentView [OK]
      Common Mistakes:
      • Calling setContentView before super.onCreate()
      • Forgetting to override onCreate
      • Not calling super.onCreate() at all
      5. You want to start a new Activity called DetailActivity from MainActivity. Which code snippet correctly starts the new Activity?
      hard
      A. startActivity(DetailActivity::class.java)
      B. val intent = Intent(this, DetailActivity::class.java) startActivity(intent)
      C. Intent intent = new Intent(DetailActivity) startActivity(intent)
      D. val intent = Intent(DetailActivity) startActivity()

      Solution

      1. Step 1: Understand Intent creation

        Intent requires context (this) and target Activity class (DetailActivity::class.java).
      2. Step 2: Check startActivity usage

        startActivity(intent) correctly starts the new Activity with the Intent.
      3. Final Answer:

        val intent = Intent(this, DetailActivity::class.java) startActivity(intent) -> Option B
      4. Quick Check:

        Intent(this, TargetClass) + startActivity(intent) [OK]
      Hint: Use Intent(this, TargetActivity::class.java) to start Activity [OK]
      Common Mistakes:
      • Omitting context in Intent constructor
      • Calling startActivity without Intent
      • Using wrong syntax for Intent creation
      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