Lab 016, Manejo De Actividades, Oncreate,Onresume,Ondestroy


Let's see we are making some adjustments to our application some details. For example, we left the video in the previous exercise. We were watching to show total consumption that we had already programmed here.

We have to remove them. Furthermore, we recover the last consumption with pending status. And then there is a force to fix doing the calculation of your totals. And if it is null, your total is zero and ours as titles fine. But this is programmed in the set in the event of the activity in the client. So that.

Means, for example, right now, it is not shown because the screen has been built, and I want to see my request. Here is my consumption. It would have to show me 120 if I go back this activity is shown again, but it does not run in create, because the application has already been created unless I close the application. It comes back.

Then runs the law. And when more exposing continued to increase here, I'm going to meats, we went to meats, and I'm going to add a thirsty barbecue today. We order and a way added.

I go back continues 120. The barbecue was not added because the activity has already been created, that is, the event with breeding. And it only runs once, simply because it is in the background, So for that, we need to understand the events that are happening within an activity. And for that I will pass you a link.

Here I am going to this link. I have already passed it to you at the class level. But look, it is on the official page of android developers that explains how to interpret the life cycle of. An activity it is already good that you give some readings, but we are going to summarize it in this graph us when we are going to load an activity our application normally when we call an activity, the on is executed, you create the first time once a creation will be executed. The OnStar is executed, which is an intermediate event then the resume. And finally, the activity is running recent. Once it is working.

It is in the foreground that is to say the user is interacting with In. This activity, it can. Happen that another activity, for example, starts working, I, don't know, We click on a button or something and call another activity, So with that, this activity goes into a paused state. And the event is going to be executed with pauses from here, Well, It can happen to us in different situations, for example, If the activity is not visible at this moment for a long time, then another event will be executed, which is the stop, And if the activity, for example, ends because the system destroys it. Since it is not being occupied.

Before a good time, and we need resources it destroys it. Then it will go to a destroy and finally the activity, and it is already totally destroyed. It can no longer be shown, but look at any of these two states of Busch or a stop if they are paused to a state. It may be that the user returns the activity as it is a stack of activities. He can return if it is in the off pause, the HOM will be executed open zoom. And again, the activity is in the foreground. And if it.

Is at a stop then the user navigates again to that activity for some reason, then the start man will be executed. And after he managed to be OnStar and after the point resume and another Once, the activity is in the foreground. If then is the user for some reason of being in a paused state, for example, some need for memory. Prioritization appears, this will go through a process of destroying the activity. But if the activity is destroyed, then it will just be will execute the man. And again, then with this.

Knowledge if we want to program in our case, we have programmed to calculate total in the country of our middle activity when it is executed, it cools it. And again, notice that when the user is going to say pay here, there is your total if he confirms the payment in this button, we have made him call this activity as we are calling it. Then there is a new call just executes the UCR.

And there again, that's, why it says update the state 0? Well, another error that also exists here in relation to the. Activities, for example, I no longer have orders and excavation and orders, but I'm going to ask for drinks. For example, let's go order a lemonade order a wine, and I'm going to order a dessert the only neighbor. So if I want to see my orders this house, the consumption and I want to pay us if I give him if I'm here in I'm in this activity, visible hours, and I'm going to pay him here from this activity, where I am seeing in the consumption I am going to confirm pause. My payment is already there and I.

Will call this activity if in this activity, it is believed that the ok was executed. But the activity from where this activity has been called is still in memory, because if I give it go back here, it is, and it says that this is my consumption in reality. I, no longer have pending consumption.

This should no longer show me. Then what happens if I give it pay here? For example, My total consumption can be confirmed, It may be that another consumption is recorded again, and it is a problem, So it is very. Important to manage the activities, what we are going to do is first pay for this, for example, If I am going to request it, I do not have it anymore, But if I am going to pay and called this I am going to delete from the stack memory that activity of this total consumption to force that the next time when he wants to enter it is executed in create, or simply it is no longer in the call stack that we had already seen. For example, in other laboratory, exercises, well, then we begin, I, repeat, Give a lady to all these events, here, he is not explaining each one of them.

And the one that we are going to execute, for example, is the congress because it is convenient for us to program here, because notice that whatever the activity will always go through it with turned if the activity is in the foreground. And then it happens to be paused, because there is another activity that is called, and then the user returns here, then he will go through the on summary, however, He is stopped for a long. Time in these, and if the user returns again, he will go to a subtract OnStar, but again, to the shoulder that then does not mean that before the activity is redisplayed.

The congestion will always be executed. So if we want to keep our total updated, when the user calls the main activity either for the first time or can return to it through the call stack, then I would have to override the event, rightly. So, because here we are right now in the man, good or mine and bets.

So here I am going to program. Some root and then here I am going to say, total consumption, let's continue. And we are going to do that event here, ready and the code of what all this would be that not all the piano, but for a little while I'm going to answer, hello, no, well, we continue then to see if you're recording, hopefully, yes, then it suits us. This We were saying that it is convenient for us to program in the sub.

Man, no. Well, then we have put a summary here, rice mode. And we call to show total consumption here. And all this code. Where we look for the last consumption, we do the calculation in titles. And we put that here, 6 then and in instead of that, I no longer need because in reality, I could call here in the country there. For example, we could call to show total consumption, but I don't need because, according to this here after six o'clock for salons, such and after the Oscar, the man is always going to go one before the activity is years old.

Then we leave it there. And every time it comes back. The honorable one will. Always be executed, and it will call again to show the consumption well with all this. And the other thing was that when we are in green, you consume the user click on the pay button.

It is called show screen confirm payment. And if the user says pay, you call register consumption, and it registers the consumption and calls the activity again, main it. But this activity here stays in memory. So that we have verified that we can go back and how to pay double. Then here before calls on the second attempt.

And what we are going to do is make that call delete from the stack of calls in all that this activity practically becomes the pirates, although we have already done that in other laboratories for that, we say, inter points. And here we are going to put constants on them. It is intense. We go to the plan activity Lucas. And we are going to add clear then with that we delete it from the light of the call stack. And then when it calls the main it can no longer go back because this activity is already. Destroyed, well, what else could we accommodate?

For example, if here this will always be updated, then yes, I want to see my drinks consumption then back. Well, we haven't made this run yet, the others that we are going to fix if I want from my with sums here. It shows me the status.

And here in this title, it says, consumption of products here we are going to put the total. And then we go. This is to see consumption. I would also have to program.

A summary here. It is correct team say we are going to play the. Same method of which we have a signal main let's check, if we don't have a consumption object already created upwards, we already have it here. It is. And here we already recover them more. Then we recover it for ideas.

And here he adds then here in here, in the show consumption, this I don't need to do it anymore, because rivers are already recovered, I simply do the because of the calculation in total and yes, Let's finally review how it was ready, He already chose then in a consumption system and. Here, the total consumption appears 60 rivers we go back I, can for example and meats, and I am going to order one barbecue costs, 120 1 very well until added back. And it is in Tibet and 180 will be the barbecue has already been updated is already active dualize. If we go in, for example, I want to see my consumption, If here you can give me the same as the total, And then for myself, from here, I will go to pay, here, I will pay him, He confirmed the order, He calls me to the main activity at 7, now, Yes, from here, I will go to him to go back.

There is no longer. It has been erased in front of the screen. So, however, the application was not destroyed just following, and my total consumption to zero. Then the user. Well here when he has no consumption, he can go to meats add products meats in the consumption.

And here it is, It is updated when he wants to see, for example, desserts, then go back, It is updated, He wants to pay here, His total consumption is always shown. And here are the lemon failure. And the pills very well, So we cancel, and he calls me here, and the other has been destroyed and all the consumption I, no longer have to go back. So I am already on the main screen to be able to make another order. And then these are details that are important You have to update that on a screen in an application. And it is very significant to know, these priorities such as the events that are chained one after another.

So that we can see according to what we need without which of these events. We would. Have to program, well that would be. Then it is with this. They complete the laboratory until it appears for its total consumption.

So that they practice a little more the handling of user interfaces, the arts, the events of the arthritis and mainly also the handling of the database with you believe very well, young people practice.

Dated : 19-Apr-2022

Leave Your Comment