Android Apps Communication A beginners Guide to Intents.
Introduction
Contemporary Android applications do not usually operate alone. They rather send messages to other parts within the application or even to other applications in the device.
Apps can use this communication to do things such as opening a web browser, sharing pictures, emailing or screen-navigating within an app. An Intent is one of the most significant processes that facilitate this communication in Android.
An Intent is similar to a message that enables one part of an Android application to demand some action by another part. Using intents, the developers are able to initiate activities, start services, or send messages to other components of the system.
In this blog, we shall discuss on what intents are, their significance in the development of Android and how intents enable Android applications to communicate with one another.
What is an Intent in Android?
Intent is a message object that is employed in Android to direct rights to another element of the application.
The Android system will know:
I would like to do a certain thing.
For example:
- Open a new screen in the app
- Share text with another application
- Open a webpage in a browser
- Send an email
- Open the phone dialer
The Android system then finds the appropriate component to handle the request.
Why Intents Are Important
Intents play a crucial role in Android application development because they allow components to communicate with each other.
1. Navigation Between Screens
Apps often have multiple screens (activities). Intents allow users to move between them.
Example:
Login Screen → Dashboard Screen
2. Interaction Between Applications
Android allows apps to interact with each other using implicit intents.
Examples include:
- Sharing a photo from Gallery to WhatsApp
- Opening a location in Google Maps
- Sending a file through Gmail
3. Decoupled Architecture
Android components are loosely coupled with the help of intents. Rather than using a direct call to another component the app dispatches an intent and allows the android system to do the calling.
Types of Intents in Android
There are two main types of intents in Android:
- Explicit Intents
- Implicit Intents
Explicit Intent
An Explicit Intent is used when the developer knows exactly which component should handle the request.
This type of intent is commonly used to navigate between activities within the same application.
Example Scenario
A user clicks a button on the MainActivity, and the app opens SecondActivity.
Java Code Example
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
Explanation
- Intent creates the message object.
- MainActivity.this represents the current application context.
- SecondActivity.class specifies the activity that should open.
- startActivity() launches the new activity.
Implicit Intent
An Implicit Intent does not specify the exact component to run. Instead, it declares a general action to perform.
The Android system finds the best application available to handle the request.
Example Scenario
Opening a website using a browser from inside an Android app.
Java Code Example
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(“https://www.google.com"));
startActivity(intent);
Explanation
- ACTION_VIEW tells Android to display the given data.
- Uri.parse() converts the web address into a readable format for Android.
- Android opens the default web browser to display the website.
Common Actions Used in Intents
Android provides several predefined actions developers can use with intents.
Action
Description
ACTION_VIEW
View data such as a webpage
ACTION_SEND
Share data with another application
ACTION_DIAL
Open the phone dialer
ACTION_CALL
Make a phone call
ACTION_SENDTO
Send an email
Example: Sharing Text Using an Intent
One of the most common uses of intents is sharing text between applications.
Get Akashgiri’s stories in your inbox
Join Medium for free to get updates from this writer.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(“text/plain”);
intent.putExtra(Intent.EXTRA_TEXT, “Hello from my Android App!”);
startActivity(intent);
What Happens Here?
- ACTION_SEND indicates that we want to send data.
- setType(“text/plain”) specifies that we are sharing plain text.
- putExtra() attaches the text message.
- Android displays a list of apps that can handle the request.
Users can then choose apps like:
- Gmail
- Telegram
Screenshot Suggestion
Insert a screenshot of the Android share menu showing multiple apps.
Intent Filters
An Intent Filter tells Android which intents a component can respond to.
Developers define intent filters inside the AndroidManifest.xml file.
Example
<intent-filter>
<action android:name=”android.intent.action.VIEW” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
Intent filters allow Android to determine which applications can respond to a specific implicit intent.
Passing Data Between Activities
Intents can also be used to pass data between activities.
This is done using Extras.
Sending Data
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra(“username”, “John”);
startActivity(intent);
Receiving Data
String username = getIntent().getStringExtra(“username”);
This method is commonly used for passing:
- User information
- Product details
- IDs
- Messages
Real-World Examples of Intents
Intents are used in many everyday mobile applications.
Opening Google Maps
When users click a location link, Android launches Google Maps using an intent.
Sharing Photos
Gallery apps allow users to share images to messaging or social media apps using intents.
Email Integration
Many apps use intents to open Gmail when users want to send feedback.
Phone Dialing
Clicking a phone number in an app launches the dialer through an intent.
Best Practices When Using Intents
Developers should follow certain best practices while working with intents.
Use Explicit Intents Inside Your App
Explicit intents are safer and more predictable when navigating between activities within the same application.
Validate Data Passed Through Intents
Always ensure that the data passed between activities is valid and secure.
Avoid Passing Large Data
Large data objects should not be passed through intents.
Instead, developers should use:
- Databases
- SharedPreferences
- ViewModel
Use Intent Chooser for Sharing
Allow users to choose the app they want to share content with.
Intent chooser = Intent.createChooser(intent, “Share using”);
startActivity(chooser);
Common Mistakes Beginners Make
Many beginner Android developers make mistakes while working with intents.
Forgetting to Register Activities
Every activity must be registered in the AndroidManifest.xml file.
Passing Too Much Data
Trying to send large objects through intents can lead to performance issues.
Incorrect Context Usage
Using the wrong context when creating an intent can cause application crashes.
Conclusion
The most potent and important aspects of Android development are intents. They facilitate interaction among various components in an application and even that of various applications in a device.
With the intents, developers can create flexible, interactive, and interconnected Android applications which would integrate well with the Android ecosystem. Intents are important whether it is between screen navigation, content sharing, or external applications, the way applications work in the Android platform.
To laypersons on the Android programming, knowledge on intents is a fundamental process in developing more advanced and dynamic mobile applications.
As developers continue their journey in Android development, mastering intents will help them create smarter, more efficient, and more user-friendly applications.





