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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Alisha Bindal
Alisha Bindal

No responses yet

Write a response