Theory
One screen is never enough
FestConnect Mobile's event LIST is one screen. Tapping an event should open its DETAIL screen, showing that event's info. Two screens, and the app must MOVE between them AND carry the tapped event's data along.
In Android, each screen is an activity, and you move between activities using an intent: a message that says 'start this screen'. You met intents in BCA305-02 with Java; here you use them in Kotlin. This lesson covers multi-screen navigation with intents, the two types of intent, and how to pass data from one activity to another.
Theory
Activities and intents
An activity is a single screen in an Android app. An intent is a message object describing an operation, most commonly 'start an activity'.
There are TWO types of intent:
- explicit intent: names a SPECIFIC target component (a particular activity in YOUR app). Used for navigation WITHIN your app:
Intent(this, DetailActivity::class.java) - implicit intent: describes an ACTION (like 'view this URL') without naming an app, letting the SYSTEM find a suitable app to handle it. Used to invoke OTHER apps (next lesson)
To actually open the screen, call startActivity(intent). This lesson focuses on EXPLICIT intents, moving between your own screens, the everyday case for a multi-screen app like FestConnect Mobile.
Practical
Explicit intent: list to detail, passing data
// In the LIST activity: open the DETAIL activity for a tapped event
fun openDetail(eventName: String, seats: Int) {
val intent = Intent(this, DetailActivity::class.java) // EXPLICIT target
intent.putExtra("eventName", eventName) // attach data (extras)
intent.putExtra("seats", seats)
startActivity(intent) // go to the detail screen
}
// In DetailActivity's onCreate: READ the passed data
class DetailActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val name = intent.getStringExtra("eventName") // read extra
val seats = intent.getIntExtra("seats", 0) // default 0
// ... display name and seats
}
}
Theory
Passing data with extras
To carry data from one activity to the next, attach extras to the intent BEFORE starting it:
intent.putExtra("eventName", eventName)
The receiving activity reads them from ITS intent:
val name = intent.getStringExtra("eventName")
Each extra is a KEY-VALUE pair (putExtra(key, value) / getStringExtra(key), getIntExtra(key, default) and so on, matching the type). So the list activity packs the tapped event's name and seats into the intent, and the detail activity unpacks them: data flows from screen to screen through the intent. This is the standard Android way to hand information to the next screen, and it is exactly how FestConnect Mobile's detail page knows WHICH event to show.
Quiz
You want to open a specific screen (DetailActivity) in your own app and pass it the event name. Which intent type and mechanism?
- An implicit intent with an action string
- An EXPLICIT intent naming DetailActivity, with the data attached via putExtra and read with getStringExtra
- No intent is needed; just call the activity's method
- A broadcast intent
Show the answer
An EXPLICIT intent naming DetailActivity, with the data attached via putExtra and read with getStringExtra
To open a SPECIFIC activity in your OWN app, use an EXPLICIT intent that names the target (Intent(this, DetailActivity::class.java)), and pass data by attaching extras with putExtra before startActivity; the receiving activity reads them with getStringExtra/getIntExtra. Option A (implicit intent) is for invoking OTHER apps by ACTION (like opening a URL), not for navigating to your own named screen. Option C is wrong: you cannot just call an activity's method to show it; activities are launched via intents and the Android system. Option D (broadcast) is a different mechanism for system-wide messages, not screen navigation. Explicit intent + extras is the standard within-app navigation-with-data pattern.
Think first
Explicit or implicit: two jobs
FestConnect Mobile needs to (a) open its own DetailActivity, and (b) open the fest's website in a browser. Which intent type for each, and why? Then tap.
Show the answer
(a) Opening your OWN DetailActivity uses an EXPLICIT intent: you know exactly which component to start (DetailActivity), so you name it directly. Explicit intents are for navigation WITHIN your app. (b) Opening the fest WEBSITE in a browser uses an IMPLICIT intent: you do NOT name a specific browser app; instead you describe the ACTION ('view this URL') and let the Android system find an app that can handle it (whichever browser the user has). Implicit intents are for invoking OTHER apps by their capability, not by name. The rule: explicit when you know the exact target (your own screens), implicit when you want the system to find an app for an action (open a URL, share, take a photo). The next lesson covers implicit intents in detail (web URLs, sharing).
Watch out
Intent traps
Explicit vs implicit confusion: explicit names a component (your screens); implicit describes an action (other apps).
Reading the wrong extra type: getStringExtra for a String, getIntExtra for an Int; mismatches return null/default.
Forgetting startActivity: creating an intent does nothing until you start it.
Unregistered activity: activities must be declared in the manifest, or launching crashes.
Passing large/complex data via extras: extras suit small data; large objects need other approaches (a shared store, ids to re-fetch).
Theory
Own screens done; now other apps
FestConnect Mobile can navigate its own screens with explicit intents and carry data along. The next lesson uses IMPLICIT intents to reach OUTSIDE your app: opening the fest website in a browser, and sharing an event to WhatsApp or other apps. Implicit intents let your app cooperate with the whole device, a hallmark of good Android apps. Then SQLite gives the app persistent storage, and location and camera add device powers.
Summary
Key takeaways
- An activity is a single screen; an intent is a message to start an activity (or perform an operation).
- Explicit intent: names a specific target component (Intent(this, DetailActivity::class.java)): for navigation within your app.
- Implicit intent: describes an action, letting the system find an app to handle it: for invoking other apps (next lesson).
- startActivity(intent) launches the screen.
- Pass data with extras: intent.putExtra("key", value) before starting; read with intent.getStringExtra("key") / getIntExtra(key, default).
- Data flows from one activity to the next through the intent's extras.
- Memory hook: explicit names the screen, implicit describes the action, putExtra/getExtra carry the data.