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.
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
- 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
Q1.An Activity is…
Q2.Which is a lifecycle method?
Q3.onCreate is called…
Pick one answer per question. - 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.kotlinclass 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
Q1.When you rotate the phone, by default the Activity…
Q2.Which pair is called when leaving to another app?
Q3.Coming back to the app calls…
Pick one answer per question. - 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