Implicit Intents — Asking Other Apps
Sprout should let users share watering tips with a friend. You could build a messaging feature... or ask the phone's existing apps to do it. Android was designed for the second option.
The rule
Say what to do, not who does it; the system finds the app.
An implicit intent names no class. It describes the job with an action and, usually, some data or a type. The system searches installed apps for one that has declared it can do that job.
val send = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "Water the Monstera every 7 days")
}
startActivity(Intent.createChooser(send, "Share tips"))Common actions:
ACTION_VIEWwith a URI — show something:https://opens a browser,geo:a map.ACTION_SENDwith a MIME type — share content.ACTION_DIALwithtel:— open the dialer with a number filled in.
If several apps match, the user picks one. createChooser always shows the picker, which is friendlier for sharing. If no app matches, startActivity throws ActivityNotFoundException, so guard it:
try { startActivity(view) }
catch (e: ActivityNotFoundException) { showMessage("No app can open this") }The shortcut
Fill in verb + object: "VIEW this web page", "SEND this text", "DIAL this number". The verb is the action; the object is the data or type.
Verb
We want to show a page →
ACTION_VIEW.
Implicit intents are for other apps. For your own screens, stay explicit: it is faster and nobody else can intercept it.
Drills
Answer fast — trust the rule.
What makes an intent implicit?
Which action shares a piece of text with another app?
Which intent opens a web page in a browser?
What happens if you call startActivity with an implicit intent that no installed app can handle?
Remember
- Say what to do, not who does it; the system finds the app.
- Build it as verb + object: action plus data or type.
- Always handle the "no app can do this" case.
