In this video, we want to have a deeper look into intense.
So what is an intent?
And intent is simply just some kind of messaging object.
So we can we can interact with other components of an application based on an intent.
Now we've got implicit and explicit intents.
And the difference is it's very simple.
Implicit simply means we do not know the destination application right now where we want to send this
intent to.
This sounds absolutely crazy, but this isn't common behavior.
And for example, let's say we want to open an email program.
So we've gotten we've gotten made to link and we want to start an email program.
So our application does know which email program we want to use.
Is it outlook email or maybe some some kind of third party application on our device?
We do not know this right now.
We simply send out this event.
Hey, we want to open an email right now.
Give us an application that can handle this and then those applications can react to this event.
Okay.
So implicit simply means we do not know what the destination application right now.
All right, then we've got explicit and yet you guessed it, explicit simply means we know exactly what
we want to start in our case right now, let's say we've gotten logging activity after successfully
logging in, we do not want to start and random application.
We want to start the profile activity in this application right now.
So this one over here by clicking on the settings button, we want to start the settings activity and
then there's also this code activity.
So within an explicit intent, we know exactly the destination.
What we want to call this can be an activity within our application or it can be also an activity with
a completely different application.
This is perfectly fine if it is exported.
Of course.
All right.
Okay.
This is only work with activities.
No, this also works with broadcast receivers and services, but it doesn't work with content provider.
We will learn more about this in several topics.
So within the content provider topic.
Okay.
So for now, we know we've got implicit and explicit intents and we can we can use intents regarding
to activities, broadcast receivers and services, even if we haven't talked about them right now.
But we will do this in a couple of videos.
Now let's have a look into some practical examples.
How do they look like and what do we need to take care of?
Okay, so we start with explicit intents.
If you take our application, then we've got here those four activities.
Explicit means we know the destination, what we want to call, for example, profile settings or code.
And regarding to really code, it looks like this one over here.
So this is the code how to start a new activity in our application.
So what we need to do is we need to create a new intent object and we have to provide two parameters.
The first one is our our current context, the blocking activity.
So our source.
And the second parameter is simply just the destination address.
In this case, it's the profile activity class.
This means we are now within the logging activity.
So of course we have to check if the username and password has been entered.
Correct.
But if this is the case, we can enter this piece of code to move on in our application.
So we simply use this start activity and then we provide our new intent object, which has been created
just the line before.
And this is the way to start a new activity in our Android system.
Alrighty.
Okay.
One last thing we need to know and then we are already mostly done with our intent.
Knowledge is that we can also provide certain information to the next instance, for example, to the
profile activity class.
We could say, for example, we are logging in as uncertain user because this information or all this
information might get lost if we are starting a new activity.
So our current activity gets destroyed and we are having a new screen content.
Yes, we could store this in in global variables, but I mean, this is not a really good approach.
We could simply pass information from one activity to another based on intents.
In this case, we are doing this for the username.
Let's say we are logging in into this application as the user admin.
This one over here.
Now in the profile activity, it would be nice if we can see which user we are now logged in right now
and also the profile data and of course the permissions regarding to this user.
We can pass this information based on an intent and this looks like the following over here.
So here we can see we are starting now an activity, but this time with parameters.
We have exactly the same two lines.
So we have our new intent object, we've got our source, our this operator, and then we've got the
destination profile activity class.
But this time we've got this intent put extra and here we can now provide certain, certain fields,
for example strings, boolean values, integers and more.
So over here we can see we we are providing a username and an admin and then we are starting this activity.
So after successfully logging in as admin, the information admin will be passed from the log.
Activity, intraday profile activity.
How does this looks like?
Well, it's not that hard.
It's shown over here.
This is the code of the profile activity.
And here we can see this.
This activity simply gets this intent with the get intent function.
And then we can access those fields via intent, get string, extra user name.
Now we can assign this username which has been passed from the logging activity into local variable
of our profile activity.
All right.
Perfect.
Because this is everything we need to know about explicit intents.
We know the destination address, what we want to call, and we also can pass certain parameters in
there.
Okay.
So now let's talk about implicit intents, this one over here.
So with an implicit intent, we do not know the destination address.
And this sounds absolutely ridiculous, but this keeps happening all the time on our smartphone.
Let's say we receive an and an SMS and this SMS has this May two string in there, like this one over
here.
If we're clicking on this, we have the opportunity to open mail application, but in this case we do
not know which mail application.
So the system is sending out this intent.
So here we are having this intent.
Hey, the user wants to open an email application, which application wants to react to this one.
And our mail application says, Oh, that's, that sounds perfectly fine for me.
I am a mail application.
I would like to open this link in, in my mail app and then the mail application appears on our screen.
So this is the story behind an implicit intent.
I mean, this would be more clear if you talk about broadcast receivers, because then it makes absolutely
sense.
But I do not want to spoil out that much right now and mix everything together.
All right.
Within an implicit intent, we have the same opportunity to pass certain information to this application,
for example, in this case, the email address.
And this is now also a little bit of a problem, because this implicit intent may be, let's say, broadcasted
to the other applications, and they can react to this one.
And so what we could do is we could we could create a malicious application that listens to this type
of intense.
So it's sniffing this, let's call it bus system for those kind of information.
And this is called intent sniffing.
This means we are having something like an Wireshark on our intents and looking for which information
are being passed between those applications.
I mean, this is not really secure channel.
It could be secure if it's being programmed correctly, but this is not often the case.
So intense sniffing could be pretty dangerous right now if you share secret information via this system.
All right.
Okay.
Last but not least, we've got our intent filters and then we we have completed this topic right now.
So what is an intent filter?
If we click on this app, I can then our launching activity will be will be launched.
I mean, that's why it's the launching activity.
These launching attributes has been defined by an intent filter.
So if you take a look into our Android manifest XML, then we can see we've got this intent filter and
we also got those two tags.
We've got an action and category tag action has the the intent action main and category has the category
launcher.
So an intent filter is really just an filter for our Android application.
There are a lot of information being exchanged all the time on our on our pass system, which we have
seen just right before the slide.
And this figure is simply just filtering them out.
So we are just listening to certain events in this example and intent with the action main and the category
launcher, which means if we click on our our app icon, then this intent will be fired and we can react
to this one.
So we can say, okay, now our application has been started, let's react to this one.
So it's simply just listening all the time to the bus system and filtering out these information are
regarding to this application.
I need to react to them and all the others.
They will be ignored.
This is what the intent filter is doing.
Alrighty.
Okay then we've got certain tags in an intent filter.
For example, we've got action.
We also got category and we've got data.
And data is not shown over here, but it can be also included in an intent folder.
All right.
Now, what's the question?
What does they mean?
And to be honest, this is absolutely confusing.
And we will look them directly up right now because I keep forgetting them all the time.
Okay.
To do this, we simply type in intent Android developer into our search engine of choice and then we
can see intent within the Android developer documentation.
So let's have a look.
All right.
And here we can see the definition of an intent.
We have already talked about this, but where can we find now those categories in action?
On the right, we can see standard actions for activities and standard actions for broadcast receivers.
We haven't talked about broadcast receivers yet, but we can already see that they got different action
names over here.
You do not have to worry about this because you will.
You will anyway look them up because no one can can mesmerize all those actions like we can see them
on the right.
It's absolutely ridiculous.
But then you get an feeling but an action is okay.
So let's have look here.
We've got actions, okay?
If we've got categories and here we can see standard, external or extra data.
So these are our three main topics actions, categories and data.
Let's have look into activity, actions we can see here we've got the action main and we can also see
the most important and by far most frequently used are action main and action.
Edit Let's see what action mean is.
Start as a main entry point does not expect to receive data input.
Nothing output, nothing constant value.
All right.
This is simply just the entry point of an application like we have already mentioned this all the time.
So we have already learned this without knowing this, that this one over here is an it's an intent
action.
Okay, cool.
What else do we have?
Let's go back.
Maybe.
Let's see.
Action, call, action, dial.
So let's see.
Action, dial, activity, action, dial and number as specified by the data.
This shows a UI with the number being dialed, allowing the user to explicitly instantiate call.
So this is simply just calling a number.
We've got an action for this one.
And so by browsing through all of them, maybe you do not have to take a look into all of them, but
into some you can feeling what this type of action is.
As already mentioned, I also do not memorize all of them.
I simply look them up.
One may be another one, which is also pretty nice is the action chooser, activity action display and
Activity Chooser, allowing the user to pick what they want to before proceeding.
But they want to before this can be used as an alternative to the standard activity picker.
This is displayed by the system when you try to start an activity with multiple possible matches.
So sometimes you get some screen.
Do you want to open it with the browser or for example, within a given application on your smartphone?
This is the action chooser.
So we've got a lot of actions for certain tasks and yeah, this is how we can use them or what they
are being used for in this case right now.
All right, maybe.
Let's have look into the categories.
Well, let's see, we've got a category launcher.
So we've got we have already looked up.
Main is simply just the main entry point and then we got this category launcher within our intent folder.
So let's see where it should be displayed in the top level launcher.
Constant value.
All right.
This sounds absolutely mysterious.
So this simply means this activity should be visible in the in the main menu.
So, for example, the app icon should be on your screen.
I guess this is how we can interpret the sentence right now.
Okay.
So the category is just bonus.
It adds additional information to our main event, our main action.
And we can also look this up in the documentation and for example, if we go back into the intent,
so on the starting page over here and then let's see.
Yes.
We've got an overview.
So action, the general action to be performed such as action view, edit or main, we have to look
them up.
But I mean, this is simply just get into the entry point of this application and things like this.
Next, we've got data which we haven't seen so far, but we've gotten a good explanation for this one.
For example, we could provide this content.
Uri, we will learn about content provider in in a couple of videos.
So here we can see we can display information about the person who is identified by the record one for
example.
So we can provide this together with an action view and then this this information are being displayed.
All right.
But we want to look up categories.
So in category over here gives additional information about the action to execute, for example, category
launch.
That means it should appear in the launcher as a top level application.
We have already talked about this by category alternative means.
It should be included in a list of alternative actions the user can perform on a piece of data.
Whatever this means, we have to go down the rabbit hole and figure everything out.
So this description isn't that helpful right now.
But we get in feeling action.
It's the action.
What we want to do category are additional information and data assembly.
Just yeah.
A data that can be provided to our to our intent.
Alrighty.
Okay.
I guess this is all we need to know.
In the next video we will do some practical examples how to interact with intense, how to provide certain
data and things like this.
So therefore, after the theory part, there's also some practical exercise we do together right now.
So I'm looking forward to see you there.