Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m

Next lesson playing in 5 seconds

  • Overview
  • Transcript

2.1 Understanding Intents

In this lesson, you'll learn what Intents are. I'll teach you what they do in Android and in particular how they help different Android components work together. I'll also give you an overview of the different types of Intents.

2.1 Understanding Intents

Let's get started with Android Fundamentals: Intents. Now what is an intent? It describes the task to be performed. It tells the Android system the request that the user has generated. It handles the requests, the request to perform certain actions. And how will the actions be performed? By allowing all the different apps in the Android device to work together. So intent allows different applications in the Android system to work together. It acts as a glue between the different Android components. Now, when I say actions, I mean, when we want to make a call, we start the request to make a call, and the intent chooses the appropriate application that will help user to make the call. When we make a request to take a picture, we use intent. When we want to share the content, we use intent. For example, if you want to share a text or image, all the list of applications available for sharing comes up. So this is when we use intent, to perform each actions in our Android device. Now intent also helps in sharing data and navigating both side. By this, I mean we can pass data to the target activity, as well as get data from the target activity to the calling activity. Let me show you an example. Now this is my Gmail application, and I have clicked Attach file button in the action bar. On selecting the option to attach file, this screen on my Android device opens up. It gives me a list of attachment, I have selected the pictures. I made a request, the intent started another activity, which gave me this list of photos in my Android device. And after selecting this image, I get this data back to my calling activity. That is my Gmail application. So here, the intent helped me to get the content of emit and then put it back to the calling activity. This way, the data can be shared back and forth. Now, intent alone cannot do all this. To do this, intent uses Intent Resolution of the Android device. Now what Intent Resolution does is it accepts the requests and dynamically matches the applications that can handle the request that is generated. For example, let's say I made a request to share an image. Now Intent Resolution comes to play. What it does is it receives this request and matches all the application in my Android device, and gives me the list which I can use to share the image. Here are a list of few applications which can fulfill, or handle, my request. So this is what Intent Resolution does. Coming to a real life example, this is one of the image in my gallery app. When I select to share this, this intent chooser comes up. And these are the list of applications that can handle my request. Now this Intent Resolution uses action, category, and data to filter the intents to handle our request. I'll tell you more about it in the upcoming lessons. Now let us see what are the form of intents that actually exist. The two types of intents are the explicit intent and the implicit intent. The explicit intents, the target for the generated request is known. We know the class to which we are targeting, so it opens the target app activity directly without giving us a list of applications. For implicit intent, the target for the request is not known. If there are multiple applications that can handle the request, we will get a list of those. And the target app is not known, hence the name implicit. We do not define the target activity explicitly. So this was all about the basics of intent. In the next lesson, we will see how do we use explicit intent to pass data from one activity to other, as well as get the response from the target activity back to the calling activity, so let's go.

Back to the top