Intents in Android Studio using Kotlin | Explicit Intent and Implicit Intent with Examples

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign welcome back to my channel in this video we will understand a very important topic that is intent we will cover all the questions like what is intent type of intents and most importantly we will understand everything through an example okay also you will find this question in every Android developer interview so make sure you watch the video till the end if you have watched any of my previous video then you must have seen that I have used intense almost everywhere because once you will start creating projects then you will realize how important intents are alright so what is intent intent is a class so basically it provides a communication between two activities or services in simple words it will redirect the user from one activity to another activity and not only that it also helps to pass data from one activity to another activity so there are two types of intent first is explicit intent and second is implicit intent okay let me explain both of them in short and then I'll explain you in detail at the time of example so explicit intent is basically redirecting from one activity to another activity within an app for example it's like going from sign up activity to login activity right then what is implicit intent so implicit intent is basically redirecting from one app to another app for example consider you are in the gallery app okay and you want to send one of your picture to someone so when you click on the share button it will provide you with multiple options of app to choose from right like if you want to send that picture through WhatsApp or through insta or maybe through Gmail correct so you choose WhatsApp now what happened over here is that you are redirected from the gallery app to WhatsApp app right this is a perfect example of implicit intent so I hope it's pretty much clear to you so now let's move on to Android Studio this is what a default Android project looks alike right we have a main activity and it's respective activity main.xms now first let's understand explicit intent example so as I said explicit intent means redirecting from one activity to another activity right so over here we already have one activity that is a main activity and we need another activity as well right so let me quickly create it and it's done so now we have two activities one is main activity and another one is second activity perfect so to redirect it we will require a button you can use text view or image view anything will work so let me quickly create a button in activity main.xml [Music] and it's done then let me quickly design the activity second dot XML as well I have wrote the text as welcome to Second activity now comes the important part so go to main activity first we need to initialize the button and then also if you are not aware about well and where then let me quickly explain it so well stands for value and it is immutable that means the value cannot be changed once it is initialized and where stands for variable and it is mutable that means it can be changed now we need to set on click listener on the button which will make it clickable so let me quickly do that and it's done then comes the intent path so first write well explicit intent this is a variable name okay then call intent class first let me write a code and then I'll explain you so inside the intent syntax we have two paths first is package context that is this which means the initial position or in which activity you are currently presenting so this referred to as main activity okay then next we have our second activity which means in which activity you want to go right so basically I want to go from this activity to Second activity perfect then use start activity method and call explicit intent that's it let's run the app and see I'll click on explicit button and it redirects me to the second activity perfect now let me show you one more key so when I click on back button it leads me to the previous activity right but I want that if I click on back button it should exit the App instead of going back to the previous activity so to do that all you need to do is add finish method and I reapply the changes and wait now let me again click on explicit button yes we are redirected to the second activity now when I click on the back button it exits the app perfect that's what we wanted right you can use finish method when you will be creating login activity so once the user is logged in and if he clicks on the back button it will exceed the App instead of going back again to the login page got it so I hope you have understood explicit Intel now let's understand implicit intent example so first let me quickly create a button for implicit intent and then I have named the button as implicit button okay so as I previously said implicit intent redirect from one app to another app so for this example we'll be redirecting from our app to another app and that another app will be the Chrome browser okay so let me quickly write the code and then I'll explain you and it's done so first I have initialized a URL that is www.google.com you can write any URL as per your choice then I have initialized the implicit button then I have set on click listener on the implicit button and inside that we have a similar intense syntax but with few different parameters so let's understand both the parameters so first is intent dot action view that represents the action of waving the data specified by the intense data so basically we just have to weave the link right so we have used action view maybe consider a different situation where you have to select a picture from Gallery then in that case we will use action pick that means selecting a picture then second parameter is URI dot parse the URI so over here URI is used to identify a resource or provide access to a particular resource then pass methods create a URI object from the given URL string so in simple words first parameter represents the action to be performed and second parameter represent on where to perform that particular action got it also as we have used link so we will provide URL but the code will be different for opening email or opening gallery or maybe opening the camera which you can easily find it on internet got it then we have called start activity method and inside that implicit intent and that's it now let's run the app I'll click on implicit button and see it will provide me with multiple app options to choose from depending upon the command so for like in our code we have provided a link right and Link will always open in browser so in my emulator there are two apps that can open this link first is Chrome and second is a tester browser so obviously I go for Chrome and the google.com is opened in the Chrome browser perfect so we have redirected from our app to another app that is Chrome got it so yeah that is it for the video and if you are new to this Channel please consider subscribing to my channel and I'll see you in the next video [Music] foreign
Info
Channel: Android Knowledge
Views: 5,033
Rating: undefined out of 5
Keywords: android studio, android studio tutorial, android tutorial, android, android activity, android development, intent, what is intent, what are intent, what is an intent, pass string, android development for beginners, pass data between activities, activities, getstringextra, between, tutorial, putextra, pass, start, how to, kotlin, newbie, objects, activity, pass data between activites using java, programming, intent in android, intents in android, what is implicit intent, android kotlin, ui
Id: CAPlP2QcHnM
Channel Id: undefined
Length: 10min 54sec (654 seconds)
Published: Mon Jun 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.