Paramclasses Academy - Blog

Tutorials Details

←
Post 14 of 40
→

How to Use Explicit and Implicit Intents in Android Studio with Java ?

How to Use Explicit and Implicit Intents in Android Studio with Java ?

November 2, 2026

1. Introduction

In Android app development, users often need to move from one screen to another or perform actions using other apps installed on their devices.

For example:

  • Opening another screen inside your application.

  • Opening a website in a browser.

  • Opening the phone dialer with a number.

  • Sharing text through WhatsApp, Gmail, or another app.

Android uses Intents to perform these actions.

In this tutorial, we will understand what an Intent is and learn how to use Explicit and Implicit Intents with Java.

2. What Is an Intent in Android?

An Intent is a messaging object that allows Android components to communicate with each other.

It is commonly used to:

  • Start another Activity.

  • Open another application.

  • Send data between Activities.

  • Request an action from another app.

For example, when a user clicks a button to open a second screen, an Intent can start that Activity.

Android mainly uses two types of Intents:

  1. Explicit Intent

  2. Implicit Intent

3. What Is an Explicit Intent?

An Explicit Intent specifies exactly which component Android should start.

It is commonly used to navigate between Activities inside the same application.

For example, suppose your application has two Activities:

  • MainActivity

  • SecondActivity

When the user clicks a button in MainActivity, you can use an Explicit Intent to open SecondActivity.

Step 1: Create a Second Activity

Open Android Studio.

Right-click your app's Java package and select:

New → Activity → Empty Views Activity

Name it:

SecondActivity

Android Studio will create the Activity and its layout file.

Step 2: Write the SecondActivity Java Code

Open SecondActivity.java.

package com.example.myapp;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
    }
}

Code Explanation:

  • SecondActivity is the Activity we want to open.

  • onCreate() runs when the Activity is created.

  • setContentView() loads the layout of SecondActivity.

Step 3: Add a Button in MainActivity Layout

Open activity_main.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <Button
        android:id="@+id/btnOpen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open Second Activity" />

</LinearLayout>

This layout creates a button in the center of the screen.

Step 4: Use Explicit Intent in MainActivity

Open MainActivity.java.

package com.example.myapp;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    Button btnOpen;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnOpen = findViewById(R.id.btnOpen);

        btnOpen.setOnClickListener(v -> {

            Intent intent = new Intent(
                MainActivity.this,
                SecondActivity.class
            );

            startActivity(intent);

        });
    }
}

Important Code Explanation:

new Intent(MainActivity.this, SecondActivity.class)

This creates an Explicit Intent.

  • MainActivity.this is the current Activity.

  • SecondActivity.class is the Activity we want to open.

startActivity(intent)

This tells Android to start the specified Activity.

Step 5: Check AndroidManifest.xml

Android Studio normally registers an Activity created through its Activity template automatically.

Check that SecondActivity is declared inside the application element:

<activity
    android:name=".SecondActivity" />

If the Activity is not registered, add its declaration inside the <application> element.

Result: When the user clicks the button, SecondActivity opens.

4. What Is an Implicit Intent?

An Implicit Intent does not specify an exact Activity or application.

Instead, it describes an action that should be performed. Android searches for an installed application or component that can handle that action.

For example:

  • Open a website.

  • Open the phone dialer.

  • Share text with other applications.

Let's understand these examples.

5. Example 1: Open a Website Using Implicit Intent

Suppose you want to open a website when the user clicks a button.

Use the following Java code:

import android.content.Intent;
import android.net.Uri;

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

startActivity(intent);

Code Explanation:

  • Intent.ACTION_VIEW tells Android that we want to view something.

  • Uri.parse() converts the website address into a Uri object.

  • startActivity() sends the request to Android.

Android will usually open the website in an available browser.

If no application can handle the request, Android may throw an ActivityNotFoundException. Handle that possibility when the action depends on an external application.

6. Example 2: Open the Phone Dialer

You can use an Implicit Intent to open the phone dialer with a phone number.

import android.content.Intent;
import android.net.Uri;

Intent intent = new Intent(
    Intent.ACTION_DIAL,
    Uri.parse("tel:9876543210")
);

startActivity(intent);

Code Explanation:

  • Intent.ACTION_DIAL opens the phone dialer.

  • tel: identifies the phone number.

  • The number appears in the dialer.

Important: ACTION_DIAL does not directly place a call. The user must press the call button.

This is different from ACTION_CALL, which directly initiates a call and requires the appropriate permission and runtime permission handling.

7. Example 3: Share Text Using Implicit Intent

Suppose you want to allow users to share a message through WhatsApp, Gmail, or another compatible application.

You can use ACTION_SEND.

import android.content.Intent;

Intent intent = new Intent(Intent.ACTION_SEND);

intent.setType("text/plain");

intent.putExtra(
    Intent.EXTRA_TEXT,
    "Hello! I am learning Android Development."
);

Intent chooser = Intent.createChooser(
    intent,
    "Share using"
);

startActivity(chooser);

Code Explanation:

  • ACTION_SEND requests a sharing action.

  • setType("text/plain") specifies that the content is plain text.

  • putExtra() attaches the text to the Intent.

  • Intent.createChooser() displays an app selection dialog.

  • startActivity() opens the chooser.

The user can select any installed application that supports sharing plain text.

8. Difference Between Explicit and Implicit Intent

Explicit Intent:

  • Specifies the exact component to start.

  • Commonly used for navigation inside an application.

  • Identifies the target Activity or component directly.

Implicit Intent:

  • Specifies an action instead of an exact component.

  • Android searches for a suitable handler.

  • Commonly used to interact with other applications.

Remember:

Explicit Intent = Open a specific component.

Implicit Intent = Request an action from Android.

9. What Is an Intent Filter?

An Intent Filter tells Android which types of Implicit Intents a component can handle.

For example, an Activity can declare that it is capable of opening web links.

A simplified example:

<activity
    android:name=".WebActivity"
    android:exported="true">

    <intent-filter>

        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />

        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="https" />

    </intent-filter>

</activity>

Important Points:

  • action specifies the type of action.

  • category provides additional information about how the component can be launched.

  • data specifies the type of data the Activity can handle.

  • android:exported="true" allows external applications to launch this Activity.

For components with Intent Filters, explicitly declare android:exported when targeting Android 12 or later.

An Intent Filter is not required just to launch another Activity explicitly within your own application.

10. How to Handle Missing Applications

Sometimes, a device may not have an application capable of handling an Implicit Intent.

You can handle this situation using ActivityNotFoundException.

Example:

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

try {

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

    startActivity(intent);

} catch (ActivityNotFoundException e) {

    Toast.makeText(
        this,
        "No application found to open this link",
        Toast.LENGTH_SHORT
    ).show();

}

This prevents your application from crashing when no suitable application is available.

11. Common Mistakes While Using Intents

1. Forgetting to Register an Activity

If an Activity is not declared in the Manifest, Android may not be able to launch it.

2. Using the Wrong Context

Use the correct Activity context when starting an Activity from an Activity class.

3. Forgetting to Set the MIME Type

When sharing text, use:

intent.setType("text/plain");

4. Using ACTION_CALL Instead of ACTION_DIAL

ACTION_CALL requires additional permissions and can directly place a call. Use ACTION_DIAL when you only want to open the dialer.

5. Not Handling Missing Applications

An Implicit Intent may not have a matching application. Handle ActivityNotFoundException when appropriate.

12. Practice Tasks

Try these tasks in Android Studio:

  1. Create two Activities and open the second Activity using an Explicit Intent.

  2. Create a button that opens Google in a browser.

  3. Create a button that opens the phone dialer with a number.

  4. Create a share button that shares a custom text message.

  5. Handle the case where no application is available to perform an action.

Practice these examples to understand how Android Activities and external applications communicate through Intents.

13. Conclusion

Intents are an important part of Android app development.

They allow Activities and other Android components to communicate and perform different actions.

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

An Implicit Intent is used when you want Android to find an application capable of performing a particular action.

By understanding both types of Intents, you can build Android applications with better navigation and useful features such as opening websites, dialing numbers, and sharing content.

14. Frequently Asked Questions (FAQs)

Q1. What is an Intent in Android?

An Intent is a messaging object used to communicate between Android components and request actions.

Q2. What are the two main types of Intents?

The two main types are Explicit Intent and Implicit Intent.

Q3. What is an Explicit Intent?

An Explicit Intent specifies the exact component that Android should start.

Q4. What is an Implicit Intent?

An Implicit Intent specifies an action, and Android finds a suitable application or component to perform it.

Q5. Can we open a website using an Intent?

Yes. We can use Intent.ACTION_VIEW with a website Uri.

Q6. Which Intent action is used to share text?

Intent.ACTION_SEND is used to request a sharing action.

Q7. What is the purpose of Intent Filters?

Intent Filters declare which Implicit Intent actions a component can handle.

15. SEO Details

SEO Title: How to Use Explicit and Implicit Intents in Android Studio with Java

Meta Description: Learn Explicit and Implicit Intents in Android Studio using Java. Understand Activity navigation, opening websites, phone dialer, sharing text, and Intent Filters with practical examples.

Focus Keyword: Explicit and Implicit Intent in Android

Related Keywords:

  • Android Intent Tutorial

  • Explicit Intent in Java

  • Implicit Intent in Android Studio

  • Android Activity Navigation

  • Intent ACTION_VIEW

  • Intent ACTION_SEND

  • Android Java Tutorial

Suggested URL Slug: explicit-implicit-intent-android-java

←
Post 14 of 40
→