What is an Activity in Android?
- An Activity is a single screen with a user interface in an Android app.
- It is like a window in a desktop app, but full-screen on mobile.
- Activities let users interact with your app.
- Each Activity handles its own UI and logic.
Key Features of Activity
- Represents one screen of the app.
- Manages UI components (like buttons, text fields).
- Handles user interaction.
- Works with intents to navigate to other activities.
- Has a lifecycle (created, started, resumed, paused, stopped, destroyed).
Activity Lifecycle
Android manages Activity states:
- onCreate():Called when Activity is created. Initialize UI.
- onStart():Activity becomes visible.
- onResume():Activity is in foreground, ready for user.
- onPause():Another Activity comes in front.
- onStop():Activity no longer visible.
- onDestroy():Activity is removed from memory.
Intent
Activities use Intents to start other Activities.
binding.btnActivity.setOnClickListener {
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)
}

No comments:
Post a Comment