Intents & Navigation
Navigate between Activities with explicit Intents, pass data with putExtra/getExtra, and launch external apps with implicit Intents.
What Is an Intent?
An Intent is a message that tells Android to do something:
- Explicit Intent — launch a specific Activity in your app
- Implicit Intent — ask Android to find an app that can handle the action (open a URL, call a number, share text)
Intents are the primary way Activities communicate with each other.
Explicit Intent: Open a Screen
Launch another Activity in your app:
// In your button click listener:
binding.btnGoToDetail.setOnClickListener {
val intent = Intent(this, DetailActivity::class.java)
startActivity(intent)
}
// To also close the current screen after navigating:
binding.btnLogin.setOnClickListener {
val intent = Intent(this, HomeActivity::class.java)
startActivity(intent)
finish() // removes LoginActivity from back stack
}