In this tutorial we will learn about Intent in android, type of intent and Android Intent example .

An Intent is a messaging object which is use to request functionality/action from other Android components. Intents are generally used to maintain the communication between different android components. An Intent in the Android application is a software mechanism that allows users to coordinate the functions of different activities to achieve a task.

Intent provide the facility to communicate between different android components like starting an Activity, starting a Service , delivering a Broadcast . Using intents, one Android component can request action from the another components of Android. Intents allow to combine loosely coupled components to perform certain tasks. Intents are instances of the android.content.Intent class. An Intents can also contain data and pass the data to the receiving components.

Read AlsoAndroid Beginner’s Guide

Types of Intent :

There are two kind of intents in android :

1. Explicit Intent :

An explicit intents are commonly used to launch an another activity ( from current activity) within the same application. Explicit intents is generally specified the component name to which the intent has to be delivered. Explicit Intents have specified a component, which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application. An explicit intent is commonly used to start an activity (from another activity) within the same application. for example : start an activity

// Start Activity :
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(i);

2. Implicit Intent :

An implicit intents are commonly used to perform some action and optionally some data required for that action. Implicit Intents have not specified the component name; instead, they must include enough information for the system to determine which of the available components is best to run for that intent. Implicit intent is used to define the action that we want to perform for different activities. for example : WebView in android

// Email Intent :
Intent email = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"+"email_id")); // mention an email id here
email.putExtra(Intent.EXTRA_SUBJECT, "subject"); //subject of the email
email.putExtra(Intent.EXTRA_TEXT, "body"); //body of the email
startActivity(Intent.createChooser(email, "Choose an email client from..."));
// Web Search Intent :
String q = "technxt code labs";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
intent.putExtra(SearchManager.QUERY, q);
startActivity(intent);

Thank you. 🙂

%d bloggers like this: