All days
Day 06Module 3 · Android Basics· 4–6 hrs

Android Basics II — Lifecycle, Configuration Changes, Intents

The Activity lifecycle is the heartbeat of Android. Learn each callback, survive screen rotation, and move between screens with intents.

0% done

Key concepts

  • onCreate → onStart → onResume → onPause → onStop → onDestroy
  • Configuration changes destroy & recreate activities
  • onSaveInstanceState / ViewModel
  • Explicit vs implicit Intent
  • Passing data via Intent extras

Lectures in this day

  1. 01

    Activity and Activity Lifecycle

    An Activity is one screen. Android calls special methods on it as it appears and disappears: onCreate (built), onStart (about to show), onResume (visible), onPause (about to hide), onStop (hidden), onDestroy (gone). Set things up in onCreate, and clean up (release camera, save data) in onPause/onStop.

    Real life · A stage play. Actor enters (onCreate), spotlight on (onResume), spotlight dims (onPause), curtain drops (onStop), actor leaves (onDestroy).

    Practice · 3 quick questions

    1. Q1.An Activity is…

    2. Q2.Which is a lifecycle method?

    3. Q3.onCreate is called…

    Pick one answer per question.
  2. 02

    Activity Lifecycle Example

    The easiest way to learn the lifecycle is to see it happen. Add `Log.d(TAG, "onXxx")` in each method, then open Logcat in Android Studio and rotate, press Home, and re-open the app. You'll see the exact order.

    Real life · Putting a small camera above every door in your house to see who comes and goes — you learn the flow by watching.
    kotlin
    class MainActivity : AppCompatActivity() {
        private val TAG = "LIFE"
        override fun onCreate(s: Bundle?) { super.onCreate(s); Log.d(TAG, "onCreate") }
        override fun onStart()            { super.onStart();   Log.d(TAG, "onStart") }
        override fun onResume()           { super.onResume();  Log.d(TAG, "onResume") }
        override fun onPause()            { super.onPause();   Log.d(TAG, "onPause") }
        override fun onStop()             { super.onStop();    Log.d(TAG, "onStop") }
        override fun onDestroy()          { super.onDestroy(); Log.d(TAG, "onDestroy") }
    }

    Practice · 3 quick questions

    1. Q1.When you rotate the phone, by default the Activity…

    2. Q2.Which pair is called when leaving to another app?

    3. Q3.Coming back to the app calls…

    Pick one answer per question.
  3. 03

    How to Survive Configuration Change

    When you rotate the phone, Android destroys the screen and builds it again — so unsaved data is lost. Save short-lived stuff (a half-typed message) in `onSaveInstanceState` as a Bundle, and read it back in `onCreate`.

    Real life · Leaving your desk for lunch: if you don't leave a sticky note where you stopped, you'll waste 10 minutes finding your place again.
    kotlin
    0
    override fun onSaveInstanceState(out: Bundle) {
        super.onSaveInstanceState(out)
        out.putString("draft", editText.text.toString())
    }
    
    1
    override fun onCreate(s: Bundle?) {
        super.onCreate(s)
        setContentView(R.layout.activity_main)
        s?.getString("draft")?.let { editText.setText(it) }
    }

    Practice · 3 quick questions

    1. Q1.One common way to survive rotation is…

    2. Q2.Another simple way is…

    3. Q3.Rotation is a…

    Pick one answer per question.
  4. 04

    Introducing Intent

    An Intent is a message that says 'please do this'. Explicit intent = 'open THIS screen' (you name the class). Implicit intent = 'anyone able to open a link, please handle this' — the OS finds a matching app.

    Real life · Explicit = calling one specific friend. Implicit = shouting 'anyone driving to the market?' and letting the first taker respond.
    kotlin
    0
    startActivity(
        Intent(this, DetailActivity::class.java).putExtra("id", 42)
    )
    
    1
    startActivity(
        Intent(Intent.ACTION_VIEW, Uri.parse("https:2
    )

    Practice · 3 quick questions

    1. Q1.An Intent is used to…

    2. Q2.Which starts another Activity?

    3. Q3.An implicit Intent…

    Pick one answer per question.
  5. 05

    View / ViewGroup and Resource Recap

    A View is one visible thing (Button, TextView, ImageView). A ViewGroup is a box that holds other views (LinearLayout, ConstraintLayout). Text, colors, and sizes go in the `res/` folder so you can change them without touching Kotlin code.

    Real life · Views are the actors. ViewGroups are the stage. `res/` is the props warehouse.

    Practice · 3 quick questions

    1. Q1.A ViewGroup is…

    2. Q2.Images in res/drawable are used as…

    3. Q3.Strings should live in…

    Pick one answer per question.
  6. 06

    Android Components Overview

    Android apps are made of 4 main building blocks. Activity = a screen. Service = code that runs in the background (like music playback). BroadcastReceiver = a small listener that wakes up on system events (like 'battery low'). ContentProvider = a way to share data with other apps.

    Real life · A restaurant: dining area (Activity), kitchen (Service), fire alarm (BroadcastReceiver), the recipe book shared with the head office (ContentProvider).

    Practice · 3 quick questions

    1. Q1.Which is NOT one of the 4 core components?

    2. Q2.Services run…

    3. Q3.BroadcastReceivers react to…

    Pick one answer per question.
  7. 07

    Module 3 Summary

    You can now build a real screen: draw it in XML, wire it in Kotlin, react to lifecycle events, save state on rotation, and move between screens with intents.

    Real life · You've gone from placing bricks to putting up a whole room with a door — next module is decorating and wiring it neatly.

    Practice · 3 quick questions

    1. Q1.Module 3 was mostly about…

    2. Q2.You should now be able to…

    3. Q3.Which is NOT in Module 3?

    Pick one answer per question.

Real-life analogies

Activity lifecycle

A stage play: onCreate = actor enters, onResume = spotlight on, onPause = spotlight dims (someone else on stage), onStop = curtain drops, onDestroy = actor leaves.

Configuration change

Rotating the phone is like the theater rebuilding the stage. If you don't save your script (state), the actor forgets their lines.

Code examples

Log every lifecycle callback

kotlin
class MainActivity : AppCompatActivity() {
    private val tag = "LIFE"
    override fun onCreate(s: Bundle?) { super.onCreate(s); Log.d(tag,"onCreate") }
    override fun onStart()   { super.onStart();   Log.d(tag,"onStart") }
    override fun onResume()  { super.onResume();  Log.d(tag,"onResume") }
    override fun onPause()   { super.onPause();   Log.d(tag,"onPause") }
    override fun onStop()    { super.onStop();    Log.d(tag,"onStop") }
    override fun onDestroy() { super.onDestroy(); Log.d(tag,"onDestroy") }
}

Explicit intent with extras

kotlin
0
val intent = Intent(this, DetailActivity::class.java).apply {
    putExtra("USER_NAME", "Rakib")
    putExtra("USER_AGE", 24)
}
startActivity(intent)

1
val name = intent.getStringExtra("USER_NAME")
val age  = intent.getIntExtra("USER_AGE", 0)

Hands-on checklist

Milestone

A two-screen app that survives rotation without losing state.

Common pitfalls

  • Storing large data in Bundle — it's for small primitives, not lists of objects.
  • Forgetting to register the second Activity in AndroidManifest.xml.