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

Connecting GitHub with Jenkins - Step by step Tutorial

Hello Everyone, In this tutorial, we will learn how to create a New Item (Project), connect Git and GitHub to Jenkins and run the files from the Git repository 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. Facing trouble with the installation of Jenkins? Click here to know more. NOTE: It is mandatory to install plugins for Git and GitHub before connecting your GitHub repository to Jenkins. If you're using Jenkins for the first time, you need to install the plugins. To know more about these plugins, check out Git and GitHub Plugins for Jenkins . This tutorial demonstrates executing python code which requires separate plugins. Know more about Python Plugi...

Statistics - MCQs

STATISTICS  This article contains few statistics MCQs related to mean, median, mode and standard deviation, asked in TCS Freshers placements. Q 1) The mean of the median, the mode and the range of the following data: 15, 10, 17, 13, 25, 17, 11, 18, 14, 19, 12, 20 a. 15 b. 16(2/3) c. 16 d. 15(1/3) Solution: c) 16 Arrange the data in increasing order- 10,11,12,13,14,15,17,17,18,19,20,25 Median = (Sum of the middle two terms)/2 = (15+17) /2 = 16 Mode = Number repeating the most number of times = 17 Range =10 to 25 = 15 Mean of median, mode and range = (16+17+15) /3 =16 Q 2) What is the mean of the mode and the median on the following data? 12, 28, 26, 27, 17, 16, 22, 25, 15, 16,...

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...