Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Intents and the Other Components  ›  Lesson

Explicit Intents — Opening Your Own Screens

Explicit Intents 13 minAn explicit intent names the exact component to start and can carry small pieces of data as extras.

Explicit Intents — Opening Your Own Screens

The user taps "Monstera" in Sprout's list. The detail screen must open, and it must know which plant to show. Both jobs are done by one small object: an intent.

The rule

Name the class, pack the extras, ask the system.

An intent is a message asking the system to do something, such as start an activity. An explicit intent names the exact component, so there is no doubt who receives it. You use it for screens inside your own app.

// In the list
val intent = Intent(this, PlantDetailActivity::class.java)
intent.putExtra("plant_id", plant.id)
startActivity(intent)
// In PlantDetailActivity.onCreate
val plantId = intent.getLongExtra("plant_id", -1L)
  • Name the class — PlantDetailActivity::class.java is the target.
  • Pack the extras — putExtra(key, value) attaches small values: numbers, strings, booleans.
  • Ask the system — startActivity hands the intent to Android, which starts the activity.

The receiver reads extras with a matching getter and a default value returned when the key is missing. Keep keys in a shared constant so the two sides cannot drift apart.

Extras should stay small. They travel through the system and have a size limit, so send an ID, not a photo. The receiving screen loads the full data itself.

The shortcut

Say it as a sentence: "Start this class, carrying this key and value." If you cannot fill both blanks, the intent is not ready.

Opening the MonsteraStep 1 of 4
  1. Name the class

    Target: PlantDetailActivity::class.java.

If the keys differ, say "plant_id" on one side and "plantId" on the other, nothing crashes: the getter silently returns the default. That is why shared constants matter.

Drills

Answer fast — trust the rule.

quick drill

What makes an intent explicit?

quick drill

Which call attaches the plant ID to the intent?

quick drill

The sender used key "plantId" but the receiver reads getLongExtra("plant_id", -1L). What happens?

quick drill

Why send a plant's ID rather than its full-size photo as an extra?

Remember

  • Name the class, pack the extras, ask the system.
  • Receivers read extras with a matching getter and a default.
  • Send IDs, not big objects, and share key constants.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainSend the right plant

Sprout's list must open PlantDetailActivity for the plant the user tapped. Explain how the list sends the plant's ID, how the detail screen reads it, and why sending the ID is better than sending the whole plant with its photo.