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

INTENTS

The document discusses different types of intents in Android - explicit and implicit intents. Explicit intents specify the component to be invoked by class name, while implicit intents only specify the general action and allow any component to handle it. The document also provides examples and differences between the two types of intents.

Uploaded by

Amber Green
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

INTENTS

The document discusses different types of intents in Android - explicit and implicit intents. Explicit intents specify the component to be invoked by class name, while implicit intents only specify the general action and allow any component to handle it. The document also provides examples and differences between the two types of intents.

Uploaded by

Amber Green
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

INTENTS

An intent is an abstract description of an operation to be performed. An Intent provides a


facility for performing late runtime binding between the code in different applications. Its
most significant use is in the launching of activities, where it can be thought of as the glue
between activities. It is basically a passive data structure holding an abstract description of
an action to be performed.

TYPES OF INTENTS

1. Implicit Intents

doesn’t specify the component. In such a case, intent provides information on


available components provided by the system that is to be invoked. For example,
you may write the following code to view the webpage.

For Example:
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(“https://www.geeksforgeeks.org”));
startActivity(intent);

2. Explicit Intents

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

For Example:
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);
HOW TO DIFFER THE TWO TYPES OF INTENT CALLING

Explicit Intent Implicit Intent


As already mentioned above explicit intents are Implicit intents do not name a
those in which the user has a clear vision and specific component like explicit
knows exactly which activity can handle the intent, instead declare general action
requests. to perform, which allows a
component from another app to
Example: When you have a Listview screen on tap
handle.
of each item you will go to detail activity
Example: When you tap the share
Intent =
button in any app you can see the
Intent(applicationContext,DetailActivity::class.java)
Gmail, Bluetooth, and other sharing
startActivity(intent) app options. Here user sends a
request is the implicit intent request
which can be handled by these Gmail,
Bluetooth-like app.

Explicit intent can do the specific application It specifies the only action to be
action which is set by the code like changing performed and does not directly
activity, downloading the file in the background, specify Android Components.
etc.

In explicit intent, you can pass data to other Here we just mention the action in
activities by using the putExtra method and the intent and OS decides which
retrieve by using getIntent(). applications are suitable to handle
the task, action across two different
Example:
applications.
val intent = Intent(this, SecondActivity::
class.java).apply{

putExtra(“key”,”New Value”)

startActivity(intent)

Second Screen:

val secondIntent = intent.getStringExtra(“key”)


Explicit intents are used for communication inside They are used for communication
the application. Like changing activities inside the across two different applications.
application.

In explicit intent, the action target is delivered When you make an implicit call with
even the filter is not consulted. the intent. OS look at the action and
then it matches with all the filters
intent-filters of all the registered
activities of all application using
PackageManager and then populates
the result as a list, this process is
called as intent Resolution.
PRACTICE ACTIVITY

1. Create an Empty Views Activity


2. Add one more Java Class File by right clicking on Project Tab’s app folder -> java ->
com.example.usingintent.
3. Type the name of the new Java Class File as “PageOne” and press enter

4. On the Project Tab’s res folder -> layout, right click and select New then click on
Layout Resource File
5. Type the name of the Layout Resource File as “page_one” and click OK button.

6. On your Project tab’s app folder -> manifests, open the AndroidManifest.xml file

7. Add the PageOne java class as another activity.


8. Open your page_one.xml and put a single button with id “btnNext” and text “NEXT”.
9. Open your activity_main.xml file and put two buttons with id and text as seen in the
image below.
10. Open MainActivity.java file and add the following code below
11. Open your PageOne.java file and import the following headers.
12. Extends the AppCompatActivity in your class name to indicate that your class is an
activity to be perform.

13. In the body of your PageOne class add the following code below.
14. Run the program to test the three button.

15. Result

You might also like