Intents in Android

Alisha Bindal
2 min readMar 15, 2021

Intent, the most fundamental component of Android. It works like a messaging component between fundamental components of Android. An intent is an abstract description of an operation to be performed.

It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and Context.startService(Intent) or Context.bindService( Intent, ServiceConnection, int) to communicate with a background Service.

What is an Intent in android?

An Intent is a simple message object that is used to communicate between android components such as activities, content providers, broadcast receivers and services. Intents are also used to transfer data between activities. Intents are used generally for starting a new activity using.

Three basic use cases of intents :

  • Starting an activity
  • Starting an Service
  • Broadcast Messaging

Types of Intents : There are two types of Android

  • Explicit Intent
  • Implicit Intent

Explicit Intent

specify which application will satisfy the intent, by supplying either the target app’s package name or a fully-qualified component class name. We use an explicit intent to start a component in our app, because we know the class name of the activity or service we want to start.

Intent intentHome = new Intent(Splash.this, HomeActivity.class);
startActivity(intentHome);

Implicit Intent

do not have a specific component, but instead declare a general action to perform, which allows a component from another app to handle it.
for eg. open link in any available browser .

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

Summary

--

--