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

Next lesson playing in 5 seconds


Free Preview: Kotlin Android Fundamentals: Intents


  • Overview
  • Transcript

The Intent is one of the fundamental building blocks of an Android app. If you want to become a pro Android coder, you're going to need to master Intents.

In this course, you'll learn everything you need to know to use Intents in your Kotlin Android app. You'll start by learning how Intents help different components of Android to work together. You'll learn how to call activities within the same app and how to use activities from outside the app. You will also see how to accept data from other apps using Intent filters.

Finally, you'll learn an effective way to test your implementation of implicit intents and custom actions using the Android Debug Bridge (ADB). ADB makes testing very easy and saves a lot of time.

1. Introduction

1.1 Introduction

Hello there. Welcome to the Android fundamentals course on intents. I'm Annapurna Agrawal, and I'll take you through the basics of intents and how to implement it to help order different components of Android to work together. We will use Kotlin for learning intents in Android. Intent is one of the fundamental building blocks of Android. And it is important to learn how it works. Using intent, we can generate the coordination between different Android components. In this course, you will learn what is intent and how it works. You'll also see how to share data back and forth activities, that is from one activity to other and vice versa, using intents. You'll see what are the types of intents and how to deal with them. You'll learn what are actions, how you can perform various actions, and categorize your activities based on that. You see how to make your application ready to work with other apps in your Android device. You'll see how to generate a request from your application, as well as how to handle a request coming from an app component outside your application. So this way, you will see how to make your app interactive both ways. From in to out and out to in. You'll learn how to define a custom action if you want to deal with a particular type of request. And then, last but not the least, cherry on the cake, I'll show you how to use ADB shell to perform testings for intent. Believe me, it makes the testing work ten times easier. I'm sure you're gonna like it. I hope you join us in this journey of Android fundamentals on intent. So see you there.

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