So now as you can see here these are the lines of code that I pasted here and now I'm going to explain
to you what's going on here.
Exactly.
So just look at this line of code here in line number 59 I just referred to the name of this fragment
my animal quiz fragment that modify animals just rose.
So as you can see here I want to actually get there actually there.
I guess those that are actually saved to the shared preferences so preference manager.
So as an argument I pass this value preference managers that get shared that shared preferences and
we need to pass the context here.
Main activity that is so in this way of any event when we are actually running the application on the
Android device we're going to actually call them if at uncreate.
Right.
And we need to actually get all these changes that are actually saved to the shared preferences we need
to get whether the user has actually changed the number of guesses or not.
We need to actually see whether the user has actually changed the types of animals that he or she wants
to be used in say the Queen or not.
We need to get the value of the backend in uncolored from the shared preferences.
We need to also get the font of the text of the patents that are saved to the shared preferences.
So it's very important that we put in these lines of code here inside this uncreate Smurfette.
So first of all we're actually calling the Smurfette my any fragment that modify animals get.
First of what we need to specify the number of throws that we have in say the keys.
As you can see here and that we pass this argument preference managers that get shared that get the
file share preferences and then we need to pass this argument main activity that does.
And as you can see in line number 60 we are calling this fragment my animalcules for argument dot modified
type of animals increase.
And now we need to be actually sure that what is going to be what are the types of the animals that
are going to be used inside the quiz.
So that's why inside this uncreate Smurfette we are calling this method modified type of animals inquiries
so we can actually specify the type of animals that are going to be used inside the application.
So my ultimate goal is my ultimate quest for argument that my dad modified type of animals increase.
And again we passed this argument pre-ferment manager don't get default shared preferences and that
we need to pass this argument this context main activity that this.
And then as you can see here in line number 61 I actually Fuerth to the name of this object my animalcules
is a fragment that modified cuius front and that means to actually get the front of the text of the
buttons from the shirt preferences.
So my argument is fragment that modified quiffs want preference manager to get default Sheth preferences.
Main activity that this.
And as you can see here my animal quest for argument as you can see here in number 62 my element for
argument that modified background color.
And then I wanted to actually get the background color of this actually of these queries.
And then I wanted to set it here.
So we are actually getting the back in uncolored of the Queen from the shirt preferences.
And then we're actually setting that back in and color to that back in uncolored of the squeeze.
Right.
So as you can see modified I can uncolored pre-feminist manages to get default shirt preferences so
this default shell preferences is actually that Shipley's for Shapley friend says that is actually specific
to our application inside the user's device.
Right.
So as you can see here professional managers that get the file shares the preferences main activity
at this point.
Now as you can see here finally we need to actually call the Smurfette reset animalcules.
So my Ahlquist fragment that reset animalcules.
So it's going I truly reset the animal cuius with those changes and then finally we need to set the
value falls for these settings changed.
Valuable right.
Because inside the uncreate Smurfette fisted have not changed the settings of the application.
When the uncreate method is called in that specific moment you are just starting to see the application
the user interface of the application and then it's going to actually do these jobs for us.
And finally you need to pass the value falls to these is settings change to valuable to assign the value
falls to these is getting changed valuable so that we can actually see these changes here.
Right.
So that we are actually sure that the settings have not changed.
We are just getting to change those settings those changes from the shared preferences and then if we
are actually setting to get here.
So now let's actually close this application here inside our emulator and now let's actually open our
menu and let me actually delete our own application here because we actually for example work when we
are working with the shared preferences it is very important that when you change the shift preferences
and when you actually for example provide more logic in order to interact with the shared preferences
it's better to always delete your application from the device so that the shirt preferences is also
deleted and then run your application again with the new actually changes.
Right.
Because we actually put lots of code here and inside this main activity AFFREIGHTMENT it's better to
actually delete our application from the device.
And now when I run my application it's going actually right it's I try to read those logic from my shared
preferences from the quotes that I provided here.
So now let's run our project and see what happens.
So as you can see we have this question and as you can see if I click on go here as you can see it says
go right.
And now as you can see here we have actually this eagle and I just need to select eagle and it says
right here.
This is animal free of pen.
So here for example I select bird and now you can see this animation.
No.
Or for example bird you can see this animation snake.
And as you can see these buttons are actually that is a belt.
And now if I click on elephant as you can see here it says elephant right.
And you can see this animation here.
And we have this rabbit.
So you just need to click on this rabbit and it says rabbit.
Right here we have snake right.
Just select snake right.
And here we have.
And as you can see here and.
Right.
And here we have a mouse.
So I just need to select the mouse.
And then as you can see here it says right here if you have a peacock so you just need to select the
peacock and here it says peacock.
Right.
And here we have actually Asharq.
So I just need to sell it short.
And here it's this short right.
And finally this is animal 10 out of 10.
And as you can see here I just need to select penguin.
And now we have this dialogue and it says 14 number of 14 number of guesses.
And seventy six point ninety two percent correct.
And here again just this thought animal quiz as you can see here.
And here you can actually go in say the settings.
I can actually change the number of options to for example six gives options and then I can actually
can you can back button here as you can see we have six options here.
I can change it to actually two number of options.
And now as you can see here our application crashed.
So we have a bug inside the application.
So now let's actually go inside the Android studio and let's see what's wrong here.
So now let me show you this sort of back here and then I'm going to explain to you what's actually the
error.
So now let me put it on our application again here.
So now I want to show you the source of the book and and then it really makes sense.
So now let me show you the emulator and now we can actually show us our application.
So now for example if I were to go inside these settings activity and at the top as you can see here
we have this back button here right.
Every time I click dispatch button here as you can see it's going to show us this activity here.
Right.
So now this means that it's going to actually create an instance of type main activity.
Every time I click on dispatch button here as you can see here the question is changes minute when I
actually click on dispatch button here right click this question.
So now let me show you my own application here.
This is the application that we built throughout this up from this lesson.
Now I want to show you the final version of the application and now you want to actually show you a
really important point.
So now in order to show you the background applications I just need to click on the spot in here and
now as you can see this is the final version of the application right.
And now as you can see I want to go to the are actually setting activity here and here.
I just want to click on dispatch button here at the top as you can see here.
Our application is actually does is not reset right.
You can see that as an instance of type this main activity is not created.
Every time I actually click on dispatch button here the same question is actually here right.
We have our snatch up here.
And as you can see here we have the same options here.
Right.
So when I go to these cities activity and I've been able to go back here as you can see the same image
is here the same options this year and the same taste is here.
But when I actually open our own application as you can see here when I go to these settings activity
now when I click on dispatch button here as you can see our application is reset and an instance of
type of main activity is created every time I actually click on dispatch button here.
Right.
As you can see an instance of type uncreate method an instance of pikemen activity is actually created
every time that we click on dispatch button here.
So this is going to create a problem a very bad problem.
This is actually a really nasty bug.
Why.
Because they did it.
The Android should not create instances of type main activity.
When I create batch put in here at the top at the top because it's going actually these instances are
not going to be removed from their memory.
And these instances are going to be actually be there.
And then when the Android device is actually going to out is going to is actually out of memory or the
application is going to actually crash or actually it's going to create a confusion inside our application.
Right.
So when I actually click on dispatch button here as you can see every time that I can expect to hear
an instance of type main activity here is created and that instance actually is going to remain there
it's not going to be removed from the memory.
So as you can see here we have one instance here and again when I click on this button he had another
instance he's created and the last instance is still in the memory.
And when I again go back here click on this box.
And here again another instance is created and this is a very bad bug.
We should not actually tolerate these kinds of bugs inside that application because it's going to actually
create confusion.
It's going to create a confusion and our application cannot handle these kinds of confusions and Android
is going to crash our application.
Right.
So we need to actually come up with an idea or solution for this problem.
As you can see we should not create an instance of take main activity every time that I can dispatch
button here.
Right.
So what squit what's the solution.
The solution is going to be inside of the manifest file.
So now let me show you the structure of the project.
So just click on this view tool windows and then click on project and then double click on this manifests
here.
So now let me actually double click on this tab here.
Android manifested exemplified in order to make this area wider as you can see here we have this application
tag.
And inside this application page we have this activity tag for our main activity class.
Right.
That main activity and this thought main activity here means that this may not be the main activity
class is actually inside of this package that the Android manifest is specified here.
The package that is a site that that animal quits.
So now inside is animal here.
You want to add another attribute.
So before the ending tag of this activity here I can just typing in launch mode and now just as you
can see here we have different options.
Single top single instance single task standard.
So because I want to have only one instance that is actually at the top of our application and I don't
want to create an instance every time that I click on this I actually click on dispatch button here
as you can see when I click on the Spike put in here.
I don't want to create another instance.
So I just want to have a single top I should activity here.
Right.
So here I can just select single type here.
Right.
So if you want to actually bring up the autocomplete here just hold the control sheet on your keyboard
and then press on Spacey on your keyboard and then choose a single top here.
As you can see here or you can just type it here right.
Single top.
And now.
Now let's actually open the emulator and now let me try to delete this application here because I told
you because you are actually interacting with the shared preferences.
It's really actually a good practice that you deal with the application from the device so that those
kinds of bad bugs are not going to be actually prevent you are not going to prevent you from actually
running your application smoothly.
So now the app is uninstalled and now let let me run our application again here so excuse me.
I actually deleted.
I actually uninstall uninstalled.
There are the final version of the application.
This is our own application as you can see so I just need to select it and I just need to uninstall
it here.
So now let me run our application here again.
So now as you can see here our application is running on this emulator for the first time.
So when I let me go inside the settings activity and now let me actually change the number of guesses
to for example 2.
And now as you can see here it says new changes are applied and now at the top or at the top.
I just need to click on dispatch button here as you can see here.
So now we have only two options.
And now let me go to these settings activity and then click on this patch.
But then here again as you can see another instance is not created here.
When I click on dispatch button here right.
We have only one single top instance.
So now let me change the number of guesses to 4 and then click on back button here as you can see we
have a Fargus options.
Now let me change it to six and then click on despite what's in here.
As you can see here now I have six options here and now I just two for example just the name of the
animal goes right.
And an animation is like here in here and you can see this the next an image.
And now let me actually select for example that I want to have on the white or I won't have only tame
animals inside the Cooley's I just select these tame animal search box and then click on OK and then
back.
As you can see now it's going to only show us tame animals as you can see here.
So I can't just for example select Dolfin and other animal as you can see here we have a horse right.
So other options so let me actually change it to wild animals and then OK back as you can see here.
Now he's going to show us all the wild animals as you can see here.
So now let me change the background color of our application to white back.
As you can see here now the back in uncolored of the application is white.
Now let me change it to for example again Blache new changes are applied and in patch as you can see
that back in uncolored is black.
Now let me change that back in uncolored of our Queen to green and then let me click on put in here
as you can see the back and uncolored is green as you can see here.
Now let me change that back in on color of the Queen to read and now it says new changes are applied
and click on.
As you can see here the uncolored of our application is red.
Now let me change the background color to blue.
Now it says the new changes are applied.
And I just need to click on dispatch button here at the top.
Now you can see that the packet uncolored of the application is actually blue.
Now let me ask you to change that by going on color to yellow.
And now it says new changes are applied.
And I just need to click on dispatch button here.
As you can see here the baguette and color of the application is actually yellow.
Let me change the font of the quiz.
So for example I want to change the front of the text of the buttons to Fauntleroy but now I just want
to select this option and then it says new changes are applied.
And I just need to click on dispatch button here at the top as you can see.
Now the phone is changed.
So now let me change it to wunderbar demo click on back as you can see here.
Now the font is changed so that sits.
And I think we actually created our most complex Android application so far.
And congratulations again.
You have created a very great Android application and now it's your turn.
Create a celebrity's cuius application and use that.
Actually the principles that I taught you in this lesson in order to create that application upload
that application to the Google Play Store.
Give me the launch of your application into Google please.
This is actually an assignment.
So please do these assignments and I'm looking forward to it.
So thank you very much for watching these tutorials.
I am going to add more complex applications to this Course discourse is going to be the best and that
overlap of course in your themi.
So just be aware of that and stay tuned.
And please if you have any questions if you have any problems please post the discussion in the course
and then I'll do my my best to answer all of your questions.
Thank you very much for watching and I'll.
And I see in the next year's Oriol.