About Intents in Android

Intents are asynchronous message which allow application components to request functionality from other Android components.

The dictionary meaning of Intent is Intention or purpose. So it can be described as the intention to do action.

Android intent is the message that is passed between components such as content providers, activities, broadcast recievers, services etc.

Android Intents are mainly used to:

  • start a service
  • dial a phone call
  • Broadcast a message
  • Display a list of contacts
  • Display a web page

The LabeledIntent is the subclass of android.content.Intent class.

An intent can contain data via a Bundle. This data can be used by the receiving component.

In Android the reuse of other application components is a concept known as task. An application can access other Android components to achieve a task.

Starting activities or services:

To start an activity you have to use a method startActivity().This method is defined the Context object which Activity extends.

The following code demonstrates how you can start activity via intent.

Intent i = new Intent (this,Login.class);

startActivity(i);

Activities which are started by other android activities are called sub-activities. To start a service via intents, use the startService(Intent) method call.

Types of Android Intents:

There are two types of Intents in android which are as follows:

  • Implicit Intent
  • Explicit Intent

Implicit Intent:

These Intents do not name a target and the field for the component name is left blank. Implicit Intents are also used to activate components of other activities.

For example-

Intent i= new Intent();

i.setAction(android.content.Intent.ACTION_VIEW);

i.setData(ContactsContracts.CONTENT_URI);

startActivity(i);

Explicit Intent:

Explicit intent going to be connected intenal world of application. Explicit Intent specifies the components. In such case,intent provides the external class to be invoked.

For example-

Intent i= new Intent();

startActivity(this,First.class));

Let’s see a simple example of Intent that take from one activity to another activity.

First Activity XML:

code 1

code 1.1

Second Activity XML:

code1

First.java

fist

In above example, there are two xml activity in which first is our main and login activity in which we take two edit text for email and password and a login button to submit the data by which on click we reach at the other activity where we take an edit text and show welcome as a text.

With the help of java we write code and by intent we connect two activities as first activity with the second.

Also Read- Model View Controller (MVC) Pattern

If you are, looking to Develop and design for your project then feel free to contact us at any time

  • Call Us- +91 9910781148, +1 8033353593
  • Email: company@tecorb.com
  • Skype- tecorb

“We maintain transparency with our customers. Our values and business ethics has given us repeated customers. We tend are proud to be a reliable outsourcing partner for many clients across the World.”

Advertisements

Author: Tecorb Teconologies

TecOrb Technologies Pvt Ltd is very fast growing company that is totally focused on Mobile Applications and Web based solutions on various domains. Over the years we have assembled a huge pool of highly skilled resources, enabled by cutting-edge tools and technologies. We build brand image of companies via digital and viral marketing so that your reach is maximized across social media sites.

2 thoughts on “About Intents in Android”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s