Welcome back and this video, we are going to take care of updating this screen or refresh and the screen
once we come back from the members activity, so we start the activity to go to the members activity
with a result this time.
And if we do that, we usually need to have a code.
So a unique code, and that's what we are going to use here.
So first of all, in the task list activity, let's go ahead and create a companion object.
Which will contain a constant value, which will be our members.
Request.
Coat, and it's going to be an integer, which I'm going to assign 13 to.
All right.
So this is the member request and the request code will be used.
And by the way, its members request, let's call it like that, and this one will be used once we get
the activity for resolved and once we start to rate the activity.
So now let's go ahead and start this activity for result.
And that is the activity once we press this button here.
So once we go and click on members, that's when we want to start the activity for result because we
want the user to go back and then come back to the screen.
All right.
So let's search for our starting the activity.
And that is done once we click on this icon, which is in our on options item selected.
So once we click on Order the action members, currently we start the activity, but without requesting
a result or without waiting for a result.
So let's change that.
So now what we're going to do is we're going to say start activity for.
Result.
And that one will be our members request code that we also pass here.
And then let's return true here, by the way, because it requires a boolean to be returned and we want
to make sure that this happens.
OK, now in our members activity, I will create a new variable, a flag, so to speak, which will
allow me to know if the word made any changes or not, because I don't want to reload the activity.
So the task list activity, if there are no changes made in the member's activity.
So I'm going to create a variable here, private var, which will be any changes.
Mate, or, yeah, any changes, mate, will be a boolean, which will be set to false.
All right.
So if there were no changes made.
Then, of course, it will stay false, but if the word changes made, we want to set that boolean to
be true.
Now, when do we know in this class that there were changes made?
Well.
We have this extra function here.
Called members science success, so we know when we add a new user, that is when the word changes made
so we can basically just add a new variable here, which will or we can assign our new variable any
changes made to the truth.
All right.
So now we will know, OK, if members assign success was called, changes were made and if that's the
case, then we can reload the whole activity.
All right.
I mean, the task list activity meaning.
This screen here can be reloaded then.
And how can we now specifically take care of that?
Well, we can just do it with this on back press functionality.
So once we click back, what we want to happen is we want this to reload.
All right.
If there were any changes made so we can just override the on back press functionality.
So override.
On back prest.
And we can just say, OK, call this super call, but also check.
If.
There were any changes made, so if changes.
Made any changes then?
Set result.
To activity.
That result.
OK, so now we just add this flag, which will be set results to result, OK, if there were any changes
made, now we can take that, of course, in our task based activity to then understand if there were
any changes made or not.
All right, now in our uncreate, we have this budget document in which we made a local variable, so
it's only visible inside of the uncreate function.
But I want to change that.
I want to make this a global variable so that we can use it outside of it as well.
So I'm going to create the private light in advance.
Which will be my ambered document ID, which will just be a string and.
We can now set and board document ID in here instead of this local variable that we had before so we
could get rid of that local variable.
Of course, we need to replace it here in first class, get more details.
Now, why would I do that?
Well, because I also want to know the board document ID when I call there on activity, result function.
So on activity result.
What I want to do is I want to check.
If the result code is success or result, code is.
Activity.
The result?
OK.
And the request code.
Was our members request code.
If that's the case, then please go ahead and reload the whole details, which means the same thing
here, show progress, dialogue, and then call this fire, start class, get more details.
All right, so here we need to import activity for this to work, of course, and then else.
We're just going to create a little Lockette log that he canceled.
Nothing too fancy.
All right.
So let's import logs as well.
And now at that point, let's test this.
All right, so that we are approaching ménage.
It needs to load the boards, so let's wait for that to happen.
That we are so there is tasks, that's the one where we saw it was created by bark, right?
And we see it in Homer's screen.
That is great.
But now let's go ahead and go to any other board.
So bored with image.
And let's add a new member here, Gerti.
We only have one potential member, right?
We only have our part.
At Gmail dot com.
Let's add him.
I can see now he's there, let's go and press the button and we can see the activity was reloaded.
So the screen was reloaded, the data was reloaded.
Of course, there were no changes made.
But this is really just for the case that you add a member and then you don't open this activity for
a while.
And a member could have changed the whole screen.
Right.
So he could have added a lot of new cards and everything.
So he was just waiting for the invite and waiting for you to add him.
And he already started doing stuff.
And you just stood idle in this member's activity and you didn't do anything else.
And when you come back, you also want, of course, to have the updated version of what has been done
on this activity.
OK, now you could, of course, say, OK, I want to reload everything each time, but in this case,
I'm doing it this way so that we don't load this activity every single time, even though it might not
be necessary.
Although you have to consider, of course, that this is a functionality that I have implemented because
we are just using a very basic version of this application, if you want to always have the updated
data.
So let's say you have added five members and you always want to see the latest data.
When you come back to the screen, you, of course, want to load that.
We get more details every single time that you get back to this activity, so not only on create, but
also, for example, on resume.
OK, so you could just overwrite on resume here.
You could just say, OK, each time you resume this activity, then I want to reload everything.
OK, but this will of course, create a lot more requests or many more requests on the database.
And if you want to optimize for requests, then the approach that I've shown you is the better one.
If you want to optimize for user experience, then you would use this on resume approach where you constantly
updated.
If you get back to the activity, you could even say, OK, it should be constantly updated or checked
with the database.
If there were any changes made and if there were any changes made, reload the page or reload this whole
activity.
OK, so that if somebody makes changes here that we see the change real time.
But for now, you know why the decisions were made this way, it's all for optimization or for cost
reduction, so to speak.
All right, so let's open up another board or actually we can even open up open up the same board.
So you could see it was preloaded.
Now, if I go to members and then I just go back, you can see the page will not be reloaded.
So there was no reload here because, well, our variable here, any changes made was false.
That's why the result wasn't set to OK.
That's why the activity result code.
This one here was not triggered and our log cancelled was triggered.
So you can even check the Lochhead out.
You can see log canceled or warning canceled or cancelled was triggered.
All right.
So that's it for this video.
And as I said, just select the version that you want to run right the way you want to optimize this
application.
All right.
So you in the next video.