Android Intents Explained – Complete Guide to Navigation and Data Passing (Kotlin & Java)

Learn Android Intents with clear examples. Understand explicit and implicit intents, navigation between activities, and passing data in Kotlin and Java.

Android Intents Explained – Complete Guide to Navigation and Data Passing (Kotlin & Java)

Introduction

So far, we have learned:

  • Activity

  • Fragment

  • Lifecycle

  • Context

Now comes one of the most practical concepts in Android:

👉 Intents

If Activity is a screen, then Intent is the message that tells Android:

“Open this screen.”

Or

“Perform this action.”

Without Intent, navigation in Android would not exist.

What is an Intent?

Intent is a messaging object used to request an action from another component.

In simple words:

Intent = Instruction to Android system.

Example instructions:

  • Open another Activity

  • Open camera

  • Open browser

  • Share text

  • Dial a phone number

Types of Intents

There are two main types:

  1. Explicit Intent

  2. Implicit Intent

Let’s understand both.

1. Explicit Intent

Explicit Intent is used when you know exactly which Activity you want to open.

Example:

Login screen → Dashboard screen

Kotlin Example:

val intent = Intent(this, DashboardActivity::class.java)
startActivity(intent)

Java Example:

Intent intent = new Intent(this, DashboardActivity.class);
startActivity(intent);

This directly tells Android:

“Open DashboardActivity.”

Real Flow (Explicit Intent)

User clicks button

Intent created

startActivity()

DashboardActivity opens

Simple and direct.

2. Implicit Intent

Implicit Intent is used when you don’t specify exact component.

Instead, you describe the action.

Example:

  • Open browser

  • Open dialer

  • Share content

Android decides which app can handle that action.

Example – Open Browser

Kotlin:

val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("https://google.com")
startActivity(intent)

Java:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://google.com"));
startActivity(intent);

Android will open default browser.

Example – Open Dialer

val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:9876543210")
startActivity(intent)

This opens phone dialer.

Explicit vs Implicit Intent

Feature Explicit Intent Implicit Intent
Target known Yes No
Used inside app Mostly Rare
Used for external apps No Yes
Example Open Activity Open browser

Passing Data Between Activities

Very common real-world requirement.

Example:

LoginActivity → Send username to DashboardActivity.

Sending Data (Kotlin)

val intent = Intent(this, DashboardActivity::class.java)
intent.putExtra("username", "Ravi")
startActivity(intent)

Receiving Data (Kotlin)

Inside DashboardActivity:

val name = intent.getStringExtra("username")

Sending Data (Java)

Intent intent = new Intent(this, DashboardActivity.class);
intent.putExtra("username", "Ravi");
startActivity(intent);

Receiving Data (Java)

String name = getIntent().getStringExtra("username");

Real Production Example – POS App

Example:

Billing screen → Pass bill ID to Payment screen.

intent.putExtra("bill_id", 1024)

PaymentActivity retrieves it:

val billId = intent.getIntExtra("bill_id", 0)

This is how screens communicate.

Intent Flags (Advanced but Important)

Flags control behavior.

Example:

intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP

Common flags:

  • CLEAR_TOP

  • NEW_TASK

  • SINGLE_TOP

Used to manage back stack.

Starting Activity for Result (Important Concept)

Sometimes you want data back.

Example:

Open AddProductActivity → Return product data.

Old method (deprecated):

startActivityForResult(intent, 100)

Modern approach:

Use Activity Result API.

Recommended for production apps.

Intent Filters (Manifest)

Implicit Intent requires intent-filter in Manifest.

Example:

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

This tells Android:

“My app can handle this action.”

Common Beginner Mistakes

❌ Forgetting to register Activity in Manifest
❌ Using wrong key name in putExtra
❌ Not checking null when receiving data
❌ Misusing flags

Always double-check keys and lifecycle.

Interview-Level Answer

If interviewer asks:

“What is Intent in Android?”

Professional answer:

Intent is a messaging object used to request an action from another app component. It is used for navigation between activities and communication with external applications.

Simple Summary

Intent = Message.

Explicit Intent → Open known screen.
Implicit Intent → Request action from system.
Extras → Pass data.

Once you understand Intent, you can build navigation easily.

Conclusion

Intents are the backbone of Android navigation. Whether you build a small app or a large-scale POS system, navigation between screens depends on Intents.

Mastering Intents allows you to:

  • Build multi-screen apps

  • Communicate between components

  • Interact with other apps

This is a fundamental Android concept.

Share

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0