← All courses

Intents & the Navigation Component

🗓 May 31, 2026 ⏱ 2 min read

What is an Intent?

An Intent is a message that says “do something”. You use it to open another screen, share text, dial a number, or open a website. There are two kinds: explicit (you name the exact screen) and implicit (you describe an action and let the system pick an app).

Explicit intent — open your own screen

val intent = Intent(this, ProfileActivity::class.java)
intent.putExtra("userId", 42)
startActivity(intent)

Read the data on the other side:

val userId = intent.getIntExtra("userId", 0)

Implicit intent — ask the system

// open a website
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://aimobilecoders.com")))

// share text (opens the share sheet)
val share = Intent(Intent.ACTION_SEND).apply {
    type = "text/plain"
    putExtra(Intent.EXTRA_TEXT, "Check this out!")
}
startActivity(Intent.createChooser(share, "Share via"))

Getting a result back

Need a result (like a picked image)? Use the Activity Result API:

val picker = registerForActivityResult(
    ActivityResultContracts.GetContent()
) { uri -> if (uri != null) showImage(uri) }

picker.launch("image/*")

The Navigation Component (modern multi-screen apps)

Instead of many activities, modern apps use one activity, many fragments, and a navigation graph — an XML map of your screens and the paths between them.

// navigate to another destination
findNavController().navigate(R.id.action_home_to_profile)

// with type-safe Safe Args
val action = HomeFragmentDirections.actionHomeToProfile(userId = 42)
findNavController().navigate(action)

Benefits: a visual map of your app, automatic Up/Back handling, and type-safe arguments.

Common mistakes

  • Passing large objects through intents — pass an ID and reload the data instead.
  • Using the old startActivityForResult (deprecated) — use the Activity Result API.
  • Creating a new activity for every screen — prefer fragments + Navigation.
Summary: Intents open screens and trigger actions; pass small data with extras. For multi-screen apps, use the Navigation Component with Safe Args.