0% found this document useful (0 votes)
155 views

Intents: Types of Android Intents

Intents allow Android application components to request functionality from other components. There are two main types of intents: implicit intents do not specify the component and provide available system components to invoke, while explicit intents specify the external class to be invoked. Intents can pass data between activities by adding extra key-value pairs to the intent object.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views

Intents: Types of Android Intents

Intents allow Android application components to request functionality from other components. There are two main types of intents: implicit intents do not specify the component and provide available system components to invoke, while explicit intents specify the external class to be invoked. Intents can pass data between activities by adding extra key-value pairs to the intent object.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Intents
Android application components can connect to other Android applications.
This connection is based on a task description represented by
an Intent object.

Intents allow application components to request functionality from other


Android components. Intents allow you to interact with components from the
same applications as well as with components contributed by other
applications. For example, an activity can start an external activity for taking
a picture.

Intents are objects of the android.content.Intent type. Your code can send
them to the Android system defining the components you are targeting. For
example, via the startActivity() method you can define that the intent
should be used to start an activity.

Android intents are mainly used to:

o Start the service

o Launch an activity

o Display a web page

o Display a list of contacts

o Broadcast a message

o Dial a phone call etc.

Types of Android Intents


1 Implicit Intent

2. Explicit Intent
Implicit Intent

Implicit Intent doesn't specifiy the component. In such case, intent provides
information of available components provided by the system that is to be invoked.

For example, you may write the following code to view the webpage.

1. Intent intent = new Intent(Intent.ACTION_VIEW);


2. intent.setData(Uri.parse("http://www.ducat.com"));
3. startActivity (intent);

Explicit Inent

Explicit Intent specifies the component. In such case, intent provides the external
class to be invoked.

1. Intent i = new Intent(ActivityFirst.this, ActivityTwo.class);


2. startActivity(i);

By using intent we can pass value from one Activity to another activity

1. Intent I = new intent(MainActivity.this, SecondActivity.class);


2. i.putExtra("Value1", "This value one for SecondActivity");
3. i.putExtra("Value2", "This value two SecondActivity");

Intent intent = new Intent (getApplicationContext(), SecondActivity.class);


intent.putExtra("myKey", AnyValue);
startActivity(intent);

We can get the passed values by doing:

Bundle extras = intent.getExtras();


String tmp = extras.getString("myKey");

You might also like