Skip to main content

Intents in Android

Hello Everyone!


This article is based on Intents in Android. Here we are discussing about intents, their types, basic intent syntax, intent filter and intent object.

From university exam perspective, intents in android is an important topic and has been asked few times along with Android Architecture and Android Components.


Intents are message passing mechanisms that are used within an application as well as between various applications. Intents in general are used to navigate users among various activities within same application or in a different application.

A classic example of intent is using intent between two different applications. Suppose a location of a place is shared on WhatsApp. When the user clicks on the location, he/she is then transferred into google map application where they can see the location on the map.

Intents are not only restricted into moving/switching from one application to other but can also be used to -

(1) Explicitly start an activity or a service by using its class name

(2) Start an activity or a service to perform some action with some data

(3) Broadcast about some event that has occurred.

Thus, we can say that intent acts as a connecting unit between the different applications installed on the device.

Intents in android are of two types -

    (A) Implicit intents

    (B) Explicit intents

 

A) Implicit intents-

It does not specify any specific component. It just declares a general action to perform and allows components from other application to handle it.

We can use implicit intent where we cannot mention any target activity.

For example, we use implicit intent to open an URL. Here we do not specify which application will open this URL. It depends on the system which application will handle this request.

Implicit intent uses the following syntax -

Intent intent =new Intent (Intent.ACTION_VIEW);

Intent.setData(Uri.parse(“https://www.google.com”));

startActivity(intent);

 

B) Explicit intents-

We use explicit intents when we explicitly name the class of the target activity that will handle the intent. Generally explicit intents are used within same application as the developer knows the names of classes present in that application.

Explicit intent can be used to take user to some different activity when the user clicks on some button or other widget.

Explicit intent uses the following syntax -

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

        startActivity(intent);

 

Intent Filter -

    An intent filter is an expression in an app's manifest file that specifies the type of intents that component may receive. By declaring an intent filter for any activity, we can allow other applications to directly start the activity. If intent filters are not declared then the application can be only started with an explicit intent.

 

Intent Object -

    An intent object carries information that the android system uses to determine which component to start (such as the exact component name or component category that should receive the intent), plus information that the recipient component uses in order to properly perform the action (such as the action to take and the data to act upon).

The various fields that the intent object consists are-

    (A) Component name

    (B) Action

    (C) Data

    (D) Category

    (E) Extra

    (F) Flags

 

A) Component name -

It is used in explicit intents which specifies the name of the activity. Without a component name, the intent is implicit. The name must be a proper class name, including the package name of the app.

B) Action -

It is a string that specifies a generic action to perform. The action determines how the rest of the intent is structured particularly the information that is contained in the data and extras.

C) Data -

It is necessary to specify type (MIME) type of data. The type of data supplied is generally dictated by the intents action.

D) Category -

It is a string containing additional information about the kind of component that should handle the intent. It is not compulsory to be included.

E) Extra -

They are key value pairs which carry additional information required to accomplish the requested action.

F) Flags -

They function as metadata tor the intent. The flags may instruct the Android system how to launch an activity and how to treat it after it is the launched.

Comments

Popular posts from this blog

How to Download and Install Jenkins on Windows Operating System.

Hello Everyone, This is a tutorial about how to download and install Jenkins on Windows Operating System. Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. PREREQUISITE- Java Development Kit (JDK) and Java Runtime Environment (JRE). Currently 1.8 and 1.11 versions are supported by Jenkins. If other versions are installed, kindly reinstall 1.8 or 1.11. DOWNLOADING JENKINS- Step 1) Go to the website https://www.jenkins.io/ and click on the download option. Step 2) In the Downloading Jenkins section, select the LTS (Long Term Support) version for Windows. It is a more stable version with new updates every 2 or 3 months. Step 3) The Jenkins windows installer will be dow

IoE (Internet of Everything) Question Paper Solution (MCQs) for 2020 Mumbai University Examination Information Technology Semester 8

Hello Everyone! This article is based on the Multiple Choice Questions asked in the University Exam for the subject Internet of Everything. These MCQs were asked in the 2020 Mumbai University-BE-Information Technology-Semester 8 Exam for the subject- Internet of Everything. The question paper for each cluster is different. These MCQs were asked in the examination of one cluster. The question paper had 25 MCQs of 2 marks each. Q 1) ________ involves making smaller and smaller things with the ability to connect and interact. a. Smart Tech b. Micro Tech c. RFID Tech d. Nano Tech Solution: d) Nano Tech Q 2) RFID stands for? a. Radio frequency identification b. Random frequency identification c. Random frequen

How to add Python Plugins in Jenkins

Hello Everyone, This tutorial is based on the different plugins required to execute python programs on Jenkins. Jenkins is an open-source automation tool written in Java with plugins built for Continuous Integration purposes. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. To execute any Python Code on Jenkins, there are two essential plugins which must be installed. The two plugins are - Shining Panda plugin and Python plugin. Following are the steps to install the plugins on Jenkins. (These steps are common for the installation of all the plugins). Step 1) Select Manage Jenkins option from the dashboard. Step 2) In Manage Jenkins, select Manage Plugins. Step 3) Now click on the Available tab. In the search bar, enter Python. (If the plugins are already installe