Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
📋 Screens, Lists & Navigation  ·  Lesson 20

Intents: Open Screens & Apps

What is an Intent?

An Intent is a message that says "I want to do something". Android delivers it to the right component — another screen of your app, or another app such as the dialer, browser or WhatsApp.

Explicit intent

  • Names the exact class
  • Intent(this, DetailActivity::class.java)
  • Open your own screens

Implicit intent

  • Describes an action + data
  • Intent(ACTION_VIEW, "https://…")
  • Android picks an app (browser)
Two kinds of intents

Explicit intent: open your own screen

Create a second screen with File → New → Activity → Empty Views Activity named DetailActivity. Android Studio creates the Kotlin file, the layout and the manifest entry.

Kotlin
// MainActivity.kt – open the detail screen
binding.btnOpen.setOnClickListener {
    val intent = Intent(this, DetailActivity::class.java)
    startActivity(intent)
}

// DetailActivity.kt
class DetailActivity : AppCompatActivity() {
    private lateinit var binding: ActivityDetailBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityDetailBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.btnClose.setOnClickListener { finish() }     // back to MainActivity
    }
}
MainActivityAndroid systemDetailActivitystartActivity(intent)create + onCreate()user taps Closefinish()MainActivity visible again (onResume)
Opening and closing a screen

Declare the new Activity

XML – AndroidManifest.xml
<!-- AndroidManifest.xml (Android Studio adds this when you use New → Activity) -->
<application>
    <activity
        android:name=".MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".DetailActivity"
        android:exported="false"
        android:parentActivityName=".MainActivity" />
</application>

Implicit intents: let another app do it

Your appACTION_SEND textAndroidwho can handle?ChooserWhatsApp · Gmail · TelegramUser picksapp opens
You do not need to know which apps are installed

Ready-made examples

Kotlin – 7 common intents
// 1. Open a website
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://codingeasily.in")))

// 2. Dial a phone number (no permission needed)
startActivity(Intent(Intent.ACTION_DIAL, Uri.parse("tel:+919000000000")))

// 3. Share text (WhatsApp, Telegram, Gmail … user chooses)
val send = Intent(Intent.ACTION_SEND).apply {
    type = "text/plain"
    putExtra(Intent.EXTRA_TEXT, "Learn Android free: https://codingeasily.in/tutorial/android/")
}
startActivity(Intent.createChooser(send, "Share via"))

// 4. Send an email
val email = Intent(Intent.ACTION_SENDTO).apply {
    data = Uri.parse("mailto:")
    putExtra(Intent.EXTRA_EMAIL, arrayOf("help@codingeasily.in"))
    putExtra(Intent.EXTRA_SUBJECT, "Doubt in lesson 20")
}
startActivity(email)

// 5. Open a place in Google Maps
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=Aligarh Muslim University")))

// 6. WhatsApp chat with a message
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://wa.me/919000000000?text=Hi")))

// 7. App settings page (e.g. after a permission was denied)
startActivity(Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", packageName, null)))
9:41▮▮ 85%Contact us⋮📞 CALL INSTITUTE💬 WHATSAPP✉ EMAIL US📍 OPEN IN MAPSShare app9:41▮▮ 85%Share via⋮🛍️WhatsApp💬🛍️Gmail✉🛍️Telegram✈🛍️Copy📋
A contact screen built only with implicit intents

When no app can handle it

If no installed app supports the action (e.g. no maps app), startActivity throws ActivityNotFoundException. Wrap it:

Kotlin – extension function
fun Context.openSafely(intent: Intent) {
    try {
        startActivity(intent)
    } catch (e: ActivityNotFoundException) {
        Toast.makeText(this, "No app found to open this", Toast.LENGTH_SHORT).show()
    }
}

// usage
openSafely(Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=Taj Mahal")))

Back stack and finish()

DetailActivitytop – visibleMainActivitystopped, waiting
Each startActivity pushes a screen; Back or finish() pops it
Kotlin – clear the back stack after login
// After login: open Home and remove Login from the back stack
val intent = Intent(this, HomeActivity::class.java).apply {
    flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
startActivity(intent)
// or simply: startActivity(...); finish()

Common mistakes

  • Activity not in the manifest → ActivityNotFoundException: Unable to find explicit activity class.
  • Using ACTION_CALL without permission → SecurityException. Use ACTION_DIAL.
  • Forgetting https:// in a URL → nothing opens.
  • Calling startActivity from a non-Activity context without FLAG_ACTIVITY_NEW_TASK → crash.

Summary

  • Explicit: Intent(this, X::class.java) + manifest entry.
  • Implicit: action + data (ACTION_VIEW, ACTION_DIAL, ACTION_SEND, ACTION_SENDTO).
  • Use a chooser for sharing and catch ActivityNotFoundException.
✅ Practice

Make a "Contact the Institute" screen with five buttons: call, WhatsApp, email, maps and share — each one using an implicit intent.

Frequently Asked Questions

What is the difference between explicit and implicit intents?
An explicit intent names the exact class to open (DetailActivity::class.java). An implicit intent only describes an action (ACTION_VIEW a web page) and Android finds an app that can do it.
Do I need the CALL_PHONE permission to dial a number?
No. ACTION_DIAL opens the dialer with the number filled in, without any permission. ACTION_CALL places the call directly and needs CALL_PHONE.
What does finish() do?
It closes the current Activity and returns to the previous one in the back stack, like pressing Back.
← Android Tutorial (Kotlin)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicPass Data Between Activities Your progress: 20 / 43 (47%) · Lesson 21 / 43 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free