‫Welcome back.
‫In this video we're going to learn about intents in Android.
‫Intents are a fundamental concept used to facilitate communication between different components of an
‫Android application, or between different Android applications.
‫An intent is an abstract description of an operation to be performed, serving as a messaging object
‫that can be used to request an action from another component, either within the same application or
‫in a different one.
‫There are two main types of intents in Android explicit intents and implicit intents.
‫In this video, we're going to learn about explicit intents.
‫Explicit intents are used when you know the target component to which you want to send data.
‫They explicitly specify the target component by providing the component name, class name, or the package
‫name of the application.
‫Let's take an example of the explicit intent.
‫I'll create a new activity inside this project, and to create a new activity inside this package and
‫you select the activity empty views activity I'll name it as second activity layout activity underscore
‫second and language is cut click finish.
‫And this is our second activity.
‫I'll change the layout just to distinguish it from the main activity.
‫So open activity underscore second.
‫Then go split mode.
‫And here I'll add a text view wrap content wrap content and the ID is my text view text.
‫This is a title.
‫Size 32 SP.
‫And here we go in further constraints.
‫And this is our layout of the second activity.
‫Back to the main activity.
‫In order to go and navigate from the first activity to the second activity we need to use explicit intents.
‫I create a button here in the main activity.
‫And infer the constraints.
‫Here we are just testing.
‫This is the layout of the first activity.
‫Let me go back to the main activity and declare and initialize this uh button.
‫So let initiate var my button.
‫It's of type button and initialize it.
‫Here my button equals.
‫To find the view by id are the ID dot my next button?
‫If you have any unexplained errors in Android Studio, just clean the project.
‫Then I need to submit a set on click listener to execute it.
‫When the user clicks on this button, I want from you to focus with me.
‫Now you create an instance of intent class specifying the current context and the target component's
‫class.
‫So val explicit intent equals to intent.
‫And here I specify this as a context of the current class and the target class, which is the second
‫activity.
‫Here I specify the type of it which is Java class Alt+ enter to import the class intent and here we
‫go.
‫This is a hint just telling us that it is a package.
‫Context.
‫Intent is a class in Android that represents an intention to perform an action.
‫It's used to request an action from another component, such as starting an activity, broadcasting
‫a message, or invoking a service.
‫This.
‫This is the first parameter in the context of an Android activity or service.
‫This refers to the instance of the current class which which is usually an activity or a context.
‫This is the target activity which is the second activity.
‫So when the user clicks on the button, this button, we need to direct him to the second activity.
‫This is the syntax in Kotlin to obtain the Java class object.
‫For the second activity class, it specifies the target component, in this case an activity that the
‫intent is directed towards.
‫So this line of code creates an instance of intent that represents an intention to perform an action
‫that involves transitioning from the current context, which is this which is assumed to be an activity
‫to the second activity.
‫This is commonly used for navigating between different screens or components within an Android application.
‫After that, we need a method to initiate the target component.
‫So we need to use start activity method.
‫And here I need to pass the explicit hint.
‫You use start activity method to initiate the target component.
‫Let me run the application.
‫Here we go.
‫This is our first activity.
‫If I click on the go to second activity button, it will direct us to the second activity.
‫Go back and back to the first activity.
‫This is how we use the explicit intent in Android.