Android Intents and Intent Filters Explained - Complete Developer Guide
In this tutorial, you'll learn how Android Intents work for launching activities, services, and communicating between app components with Kotlin examples.
What You'll Learn
how Android Intents work for launching activities, services, and communicating between app components with Kotlin examples — Intents are the backbone of Android inter-component communication. Every screen transition, service start, and broadcast depends on them.
Why It Matters
Intents are the backbone of Android inter-component communication. Every screen transition, service start, and broadcast depends on them.
Real-World Use
A ride-sharing app uses an implicit intent to launch Google Maps for navigation, and explicit intents to move from login to ride-booking screens.
Learning Path
flowchart LR
[Android Basics] --> [Intents & Intent Filters] --> [Activities & Lifecycle] --> [Fragments]
style 2 fill:#4CAF50,color:#fff
Explicit Intent - Starting an Activity
val intent = Intent(this, DetailActivity::class.java).apply {
putExtra("KEY_ID", 42)
putExtra("KEY_TITLE", "Hello Android")
}
startActivity(intent)
Expected output: DetailActivity launches and receives extras: KEY_ID=42, KEY_TITLE="Hello Android".
Implicit Intent - Opening a URL
val url = "https://dodatech.com"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
// Share text
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "Check out DodaTech tutorials!")
type = "text/plain"
}
startActivity(Intent.createChooser(shareIntent, "Share via"))
Expected output: The browser opens with the URL, or a share chooser dialog appears.
Intent Filter Declaration
<activity android:name=".ShareReceiverActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
Expected output: Your activity appears in the system's share chooser for text content.
Deep Link Handling
class ProfileActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleDeepLink(intent)
}
private fun handleDeepLink(intent: Intent) {
val dataUri = intent.data ?: return
val userId = dataUri.lastPathSegment
// Load user profile for userId
}
}
Expected output: ProfileActivity extracts the user ID from the deep link URI and loads the corresponding profile.
Common Errors
- Missing CATEGORY_DEFAULT in intent filter prevents implicit intent resolution
- Null intent extras crash without default values - use getIntExtra(key, default) pattern
- SecurityException when starting services with implicit intents on Android 5.0+
- Deep links not opening your app - autoVerify=true requires HTTPS and a hosted assetlinks.json
- No Activity found to handle intent - check action string and MIME type match exactly
Practice Questions
What is the difference between explicit and implicit intents?
What components can be targeted by an intent?
How do you pass custom Parcelable objects via intents?
What is autoVerify and why is it needed for Android App Links?
When should you use the Activity Result API instead of startActivityForResult?
Challenge
Build a 'Share to App' receiver: create an activity that handles ACTION_SEND for text, extracts the content, and displays it in a TextView. Test by sharing from Chrome.
Real-World Task
Implement deep linking in a Jetpack Compose app with NavDeepLink. Configure intent filters for https://myapp.com/products/{id} and navigate to the correct Compose screen.
Frequently Asked Questions
{{< faq question="What is the difference between startActivity and startService?">}} startActivity launches an Activity (UI screen), while startService starts a Service (background task without UI). Both use Intents. {{< /faq >}}
{{< faq question="Can an intent filter match multiple data types?">}}
Yes. Declare multiple elements in one
{{< faq question="How do I pass custom objects in an intent?">}} Implement Parcelable or Serializable on your class. Parcelable is faster and recommended. Use putExtra with the appropriate method. {{< /faq >}}
Security Tip: When receiving implicit intents, always validate the data URI and extras. Malicious apps can send crafted intents. Use PackageManager.queryIntentActivities to verify the responding app is trusted.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro