First of all I actually created an object of type intent as you can see here.
So intent intent knew intent and here.
And when I actually go from this main activity class to this main activity class.
So when the user clicks on the notification I want to actually move to this main activity.
OK.
I can actually specify other activities but for this application I just wanted to show you how to use
notifications and how to create and manipulate notifications.
So it is going to be a little bit simple.
So just a new intent and I want to actually move to this main activity class so here as you can see
for the first argument I specified this May 9th main activity that this.
So this is going to be the context and for the second argument I actually specified main activity that
class.
So this means that you want to move to this main activity class here.
OK.
And in line free.
I actually created an object of type pain.
Intent.
OK.
So let's actually open our web browser and let's actually go to Android documentation and see what is
this pending intent.
So now let's actually open our browser and here in the search bar just typing here pending intent.
And here as you can see we have this pending intent inside this android that app package just select
it and click on it.
So now we are actually guided to this page.
So as you can see here we have these pending intent class.
This is actually a public class final class pending intent.
OK.
So now here is our description.
So a description of an intent and target action to perform with it in instances of this class are created
with good activity.
This is actually an effort that we are going to use for our notification.
So here as you can see it says by giving appending intent to another application you are granted get
the right to perform the operation you have specified as if the other application was yourself.
OK.
With the same permissions and identity as such you should be careful about how you build the dependent
intent almost always the base intent you supply should have the component name explicitly set to one
of your own components to ensure it is ultimately sent there and nowhere else are pending intent itself
is simply a reference to a token made maintained by the system described me in the original data used
to retrieve it.
This means that even if it's own applications process is kid is killed depended intent itself will remain
usable from other processes that have been given it.
If they create an application Leader Reid retrieves the same kind of paper and an intent same operations
same intent action.
Or categories and components and same flags it will receive appending intent representing the same token
if it's if that is still valid and you can call cancel to remove it.
So now let's actually look at some of the merits of this class.
So as you can see here these are the public Moffats can sell the scrap contents equals good activities.
And we have some of the effects of this class.
So let's go back to our Andrex studio here.
I want to specify that when the user clicks on the notification I want to update the current main activity.
OK I want to actually guide the user to the current activity so I need to create this intent.
OK so pending intent that gets activity this is actually a method that is inside of this class main
activity that this sort of first argument is going to be the context main activity that this the second
argument is going to be the request code.
OK.
That is that it's going to actually specify that this notification is actually specific only to this
activity.
OK.
So we can have multiple notifications in that application so we use this request code to identify are
not notifications so this notification has this request code number zero.
OK.
And the intent.
The argument is going to be the intent.
So to actually if we want to actually move to this activity to this main activity so I put I actually
assigned this intent here.
And for the last argument we need to put the spent in intent that flag updates colorant.
So let's actually go back to what Android documentation again and here let's actually search for.
So here I just need to hold the Comanche and then person F key on my keyboard.
So if you are using a Windows machine you need to hold the control key and then present their key on
your keyboard and then here I just need to type in Flag updates current update current.
I just need to click on this flight update calendar here and as you can see we have these flight updates
current and it says that a flag indicating that if they described pending intent already exists then
keep it but replace its extra state of it in this new intent OK flag indicating.
So let me actually read it again.
Flag indicating that if they describe the painting intent already exists then keep hit but replace it's
extra state with what is in this new intent for use with get activity.
So as you can see here we are using these activities that activity Meffert here.
This can be used if you are creating intense but only Dijkstra's change and don't care that any entities
that received your previous pending intent will be able to learn it with your new extras even if they
are not explicitly given to it.
So here because we want to actually only move to our main activity again we can actually use this a
flash update current and we can actually update some information in our activity.
Okay.
And that's the purpose of this flight update current.
OK.
He's going to actually keep the same intent as you can see here depending.
Intent already exists.
Ok then it's going to actually keep it but replace it throw it data.
OK.
So we may have some extra data but this can actually replace those data.
OK.
So if we use this flag update current and in line of 57 as you can see I called this builder that said
content intent pending intent.
OK.
So here I am actually setting the content intent on this up here.
With that said content intent and then intent I passed is pending but opinion intent.
Object to the Smurfette and in line 59.
I am actually creating an object of type notification manager.
OK so notification manager.
And then the name of this object is notification manager.
And here I am casting this object to a notification manager object.
And here I am calling this method get system service notification service.
So we need to actually get the system serviced notification service.
It is very important in order to actually create a notification in our application.
OK.
So notification service.
So I am actually getting this notification service and I am assigning to this notification manager that's
value and in length 60.
I am calling this notification manager that notify.
OK.
And the first argument is going to be detach.
So I called dispatch notify.
OK you can call it whatever you want.
And the second argument is client is going to be the ID of this notification manager.
So I assign this value one hundred twenty three.
One two three.
And you can assign whatever value you want.
So it is going to be an integer value.
OK this is going to be the ID and the Fred argument is going to be the builder that built.
So I referred to the name of this object builder and I called the Smurfit build.
So now we need to actually Conti's Schoener to vacation Meffert in our unclick if it here.
So here I can just type in show notification.
So now let's run our project and see what happens.
So now as you can see here our application is running on this emulator here.
So now for the title of the notification I can just type in title and for the text I can just type in
text.
OK.
So let's actually click on this button here.
Notify me so now as you can see we have a notification.
So let's actually right here.
And as you can see we have this notification and the title is title and the text is text.
And we have this icon here.
OK.
So let's see if we actually click on this notification here.
Now we are guided again to this activity.
And as you can see it here the the data is actually updated here as you can see because we are actually
moving again to this activity.
So it's going to call the uncreate method here again.
So now as you can see the data is gone.
OK.
So hopefully that makes sense.
So now as you can see if I actually click on this notify me again here without assigning a value to
these text fields.
So if you actually look at the notifications here now as you can see again it's actually created our
notification here for me but without the title and the text.
So I don't want to allow the application to create a notification without the title and the text.
So here inside is main activity class.
Inside is Uncle Meffert.
I can actually create an if statement so if it's the content title that get text that to a strange dot
matches and here inside the practices of this matches here matches Mefford I just need to put two double
quotes and this means that if the value of this text here as you can see if the value of this Edhi text
is actually empty.
OK.
And here let me actually create an all logical operator or EDT a content text.
This time I referred to that with this name in it its content text.
Ok that's good text that too strange that matches.
OK.
And here again I need to two double quotes here without assigning any value to these inside these are
two double quotes.
So I just need to open and close this statement by using these curly braces as you can see here.
So let me create a new line here so that you can see this.
This piece of code he had better and now I can just type in return.
And this return here means do not execute this method anymore.
This unclear if it anymore is going to actually break out of the Smurfit break out of the Smurfit.
It's not going to execute this method anymore.
Until we actually click on that button once again.
OK that's the meaning of this router.
It's not going to execute this short notification method.
Here if this expression hit evaluates to true if one of these expressions here evaluates to true it's
going to return and it's going to it's not going to execute this uncle anymore.
I need to actually click on that button again in order to execute this method again.
OK.
So I put this written statement here.
And if if this expression evaluates to true he's going to return and it's not going I should execute
this line I've got here.
So let's run our project again and see what happens.
So now as you can see our application is running on the simulator.
So if I actually click on this button here again and now as you can see it's not going to actually create
notification for me because I didn't assign a value to this text.
Eddie texts as you can see here.
So if I actually assign a value for the title and if I don't assign a value for the text of this notification
and if I click on this notify me again here it's not going to create a notification for me because I
use this or operator here.
OK.
I said that if this expression even evaluates to true or if this expression evaluates to true then it's
going to execute this return statement and it's not going to execute.
And I've got here.
OK.
So I need to actually assign a value for the content text and if I notify me and if I actually click
on this notify me button here again.
And as you can see here it actually created this notification for me.
OK.
And if I click on it again.
Now we will be guided to this main activity class here again.
So hopefully that makes sense and I think that's enough for this tutorial.
So here I just wanted to show you how you can actually create on notification later in discourse of
we will be creating a more complex application and we will be using some of these features some of these
notification features in our application.
So for now I just I just want to show you the basics of creating a notification in Android application.
So thank you very much for watching.
And if you have any questions regarding notification in Android please post the discussion in the course
and then I'll do my best to answer all of your questions.
Thank you very much for watching and I'll see you in the next year or two earlier.