Welcome back.
Now, there is one less thing to do in our application, and that is to finish the results screen.
So what do we need on this result screen?
Well, we need the user name and we need to have the amount of correct answers and, of course, the
amount of total answers.
So these are information that we need to send over to the screen.
And where do we get them from?
Well, we get the user name from our first activity, which is our main activity, and we can pretty
much get the other two from our constants variable.
So here in our constants variable, we can go ahead and create.
Several new constants.
Which will be concert value, this one will be on the score username.
I'm going to set that to being a string and I'm going to call this one username, then const value.
And here, of course, I'm saying value, but it's about it's an immutable variable.
So then we have total questions, which also will be a string of type total questions, or at least
that's going to be the entry in there.
And then finally, another variable, which will be the correct answers, which will also be correct
answers as a string.
So why do we even need them?
Well, if we go to our main activity now.
To open up here, the main activity we can see that we have this intent and this intent sends us over
to this quiz questions activity.
So we need to put some extra information into this intent so we can go ahead and say put extra.
And what do we want to put extra?
Well, first of all, we need to have a key, so to speak.
And that will be the username that we sent here.
So constant thought user name is going to be.
And what is the user name?
Well, we get the user name from the user entering his name into name so we can just go ahead and read
that from there.
We can just say it.
Underscore name, dot text.
Not to string.
So now we sent this information over with the intent to the next activity, which is our quiz questions
activity, because we move over to this activity by starting this intent, right.
So we now can retrieve this information in the next activity, which is our quiz questions activity.
So here, I'm going to create another variable at the very top.
Which will store the username so far and user name, which will be of type strength nullable, and I'm
going to set that to now for now.
All right, so now, of course, I need to set the username and how can I set it?
Well, I get the username from the intent so I can do it in the uncreate, because as soon as the uncreate
is fired, we already were sent over and the intent has already sent its extra information, which we
have put in the main activity.
So here we can go ahead and retrieve this information by storing it in our username variable, which
is in 10 thought get string extra.
And now at which position was the string extra?
Well, it was at this position here.
So that's the key.
That's pretty much the name, not the username itself, but the name of the username key.
All right.
So it's going to be this one here.
So now we get the username, whatever the user has entered in the main activity over to this activity
here, which is our quiz questions activity.
Now, the thing is, in this activity, we don't even need it.
We just need it in the results activity.
But the thing is that we have this flow that we move from the main activity over to the questions activity,
then over to the result activity.
All right.
So this is one way to do it.
So we sent it over with intense each time.
Of course, we can also store it on the device each time and override it by using.
Shared preferences, but in this case, we're going to keep it simple, we're just going to send it
over to the activities via the put extra functionality.
All right, now we need to find the right spot to move over to the result activity, and that is in
the unclick when we click submit.
So once you click submit and we move over to the next screen, or we should move over to the next screen,
which is here currently we have this make text here, but instead, at this point, we want to move
over to the next screen.
Right.
So we need to create a new intent.
So let's go ahead and do that.
So intent is going to be a new intent, which needs to have the context.
And of course, we need to import intent.
So let's do that and enter to import it and then.
We need to say to which screen we want to move over, and here it's the result activity.
Class The Jawa, and here is a colon twice, so double colon, so that's our intent now the intent itself
is ready.
But the thing is, I want to give this intent additional information, so I want to put some extra info
to it.
So I'm going to use put extra here again.
You could see there are many different overwrites for put extra many different options.
So either we pass a new string or we pass an integer and so forth.
So we could pass a lot of different information in there, but we just couldn't use the same function
every time.
So we can just pass different information if it's going to use the right information every time.
So first of all, it needs a string.
So here constants that username.
So we're just going to use the user name again to pass it over.
And where do we get it from where we created this variable called M Name, which we created here at
the very top.
So he had a username and then we filled it in the uncreate here and now we use it when we pressed the
submit button.
All right, so that's our first intend to put extra.
Then we need to put some more information extra in.
I told you which ones they are.
So if we look at our result activity, we can see it's the amount of correct answers and it's the amount
of total answers.
All right.
So let's put this extra information here, Constance Dot correct answers.
And it's the correct answers variable that we created.
And then another in turn put extra where we put the extra total questions so constants, not total questions,
which is our M questions.
List that sites.
I know the questions, this is a nullable, so we need to focus on Rapide here or force here, and of
course, we can start this activity with that intent that we prepared.
OK, so here we put all the extra information, so this is the key and this is the value and we have
different keys and we prepared those keys to be constants so that we can always use them with the same
name, so to speak.
And we don't have to write them here manually because here the correct answer constant is, of course,
going to be correct answers.
All right, so at this point, we send it over and now we, of course, need to receive it and retrieve
it in the result activity.
So when we get to the result activity, and that is in the uncreate, that's where we get this information.
But we need to use it.
So we need to catch it, so to speak.
All right.
So in order to get the username, we can just create a variable here called username and we get this
from the intent.
So get string extra at the position constants dot username.
And now we can use this name to set it as the TV on the screen.
Name the text, which is going to be the username that we prepared.
So that one here.
And what is the TV name.
It's our to you and the activity result here, which is this text TextView called TV name.
So this one where it currently says username.
So we need to import TV name, you can see here it needed to have this import.
Which just this one here and now we can use it, all right.
So we said the user name.
Now we need to set the score text, which is, of course, going to be dependent of two values.
So one is going to be the amount of correct answers and the other one is the amount of total questions.
So while total.
Questions.
That's going to be intense, get into extra this time, because if we look at it.
Here we sent over incorrect answers, and it's an integer.
All right, so we need to pass in the right value, of course, and we need to get the right value here
so we're not getting a string as we did before, but we get an int.
So get into extra is going to be constant, start total questions.
And now volle correct answers will be and tend to get into extra because the correct answers is also
an amount.
So it's also an integer constants.
Correct answers.
Now, the thing is, you can see that it's complaining here when you get an index drum that something
is missing and that is because something could go wrong in that process.
So if something is missing, then I wanted to use the default value of zero.
So I'm going to do that in both cases.
I'm just going to say the default value will be zero.
So if for whatever reason it wasn't sent over, then use zero as the alternative value or as the default
value.
All right.
And at this point, we can go ahead and say TV on this score score.
The text is going to be your score is and then the correct answer.
And maybe I should call it correct answers.
Out of and then total questions.
All right, so then if we look at our activity result, you can see here we have this finish button.
So this button currently doesn't do anything and it's inside of our result activity, of course.
So what would make sense to give this button?
Well, I'd say it would make sense to give this button the functionality of when it's clicked that it
sends us over.
To the main activity, so you can, of course, create an intent and then in the next step used to start
activity, but you can also pass in a new intent directly here.
So you can directly say this and then send me over to the main activity code and class that Java.
All right, now, intent needs to be imported here as well, so let's do that real quick.
And that should be it.
So now we have everything prepared and we can test our application.
All right, so I'm going to use my name here, Dennis.
Now, I'm going to go through all of the questions here.
And now let's submit the last two answers and we can see we get to the results screen your score is
ten out of ten, it says then here as we have entered into first activity in the main activity.
Now let's finish and move over to the main activity.
All right.
Now, at this point, of course, we can still go back because we didn't finish this activity.
But that's something that you can, of course, do here as well.
So you can just say, OK, finish now.
This will close the activity.
Another thing, if we look at this activity, we see that at the top.
We have the status pass.
Of course, we can get rid of the status bar as well by just using the same line that we had, the domain
activity where we said, OK, to activate this place.
So let's just do that in here as well and then it will be fine.
So testing it again, we will see that those two features now have been implemented.
So I'm going to say test here this time, so it will be a different name.
I'm going to make some mistakes this time, going to go real quick through this.
I want to make plenty of mistakes.
Doesn't matter.
And then let's finish and we can see your scores, three out of ten now let's finish close the activity,
because when we go back now, you can see we go back to the quiz activity.
Now, of course, you could go ahead and say, all right, I don't want to have the quiz activity as
well.
So maybe it makes sense to go to a quiz, questions activity and once we move over.
So once we sent this intent here when submitting, we also finish the current activity.
All right, so that was it.
I hope you enjoyed this chapter, so we created this little app.
Now, of course, you can go ahead and change your constants, which means change your questions.
You can change the amount of questions you have.
You can change the type of questions you have.
You can use different images and so forth.
So you pretty much have created a whole quiz app that you can now adjust to your liking and then sent
to your friend's publisher to restore whatever you like.
All right.
So I hope you enjoyed this and thanks a lot for being part of this and see you in the next one.