exclude. Okay, Okay, good start recording good morning. everyone. So got a question on on the So I've just started a poll for how you all how things were with the midterm.
So it's going to be another week from midterms I had some other stuff I had to take care of.
First you should have assignment 2 grades soon, and assignment 3.
First of all, at least assignment 3 which I should be doing with the next couple of days.
Let's see how that pull looking I will end the Poll.
Okay, so that's good most you thought was reasonable reasonable is what I'm hoping for.
What the Mitchell had come out with the midterm was.
It was our last class period in time when it's too long.
Okay. Assignment 3 will be Android studio.
Yes, now, rest of terms on android. if you missed the poll.
You missed the poll don't worry about it but yeah if you're if you have problems with a poll make sure you're running a current version of android studio not not android studio I mean zoom that doesn't
make more sense. Question: What Yeah, I will go up once i've released grades.
We'll go for answers and then we'll I'll set up the interviews and stuff.
So Oh, Rosie wants to come. Say, hi! now, come on, Rachel!
Come on, Rosie, Hey, Lucy, Hi! saying, hide the class!
What is it Okay, sad Doc, but let's don't drop my floor.
Okay, let's go ahead and talk about now, let's go to Android.
That's so, but inside let me i'm switching windows on you here.
So we're, Now here have the midterm we have this may, you know, you know, lectures until April eighth.
We have, you know. today we have 4 more tutorials, 2 more assignments.
So right now we have assignment due march the 20 third.
I'd like to be a little more time on that but I should have that coming out soon for and Then we'll, and you'll have a last assignment that we do in the last day of class what We've
but what we're talking now about is android and hopefully, most of you got a chance to do tutorial 6.
I know a lot of you have not gotten checked off on Tutorial 6.
But so you should definitely make sure you're you know get that done and get Android running after i'm done with lecture.
I'm happy to help people get android working you know do check off your tutorials.
So the new tutorial for today is actually pretty simple.
But involves some important concepts to step back on how Android works.
So if we if you look at tutorial 6 I kind of just threw you into it, saying, Okay, here's get android studio running here's your code.
Go do stuff this tutorial we're going to step back and kind of go up actually happening here.
And in particular we're going to talk about so so this is the program.
So this is a really simple program. I will get it running here.
To work. Okay, the issues you should you get the idea of it's actually building.
And here in my fan, can you hear the fans going on?
My laptop. it's just sad how much well, this is the emulate.
Let's take no care more here. we go okay, I I took care of that.
So now this is how the app starts so top me you're on top.
Yet you start cabin now, and then, when you rotate it does this thing, It doesn't say you haven't talked yet, but it remembers this.
Why does this matter? Why is that like Okay, big deal you know we've seen this? Yeah, i'm right.
This is the code for tutorial 7. Yes, exactly.
This is just so It This is exactly the code for tutorial 7.
This tap. demo so open for a research let's go back to text Analyzer 5.
Where first, but he doesn't know open decent okay so here we go.
This is text Analyzer 5. If we run this in the same.
Okay here. Good. So here's text analyzer 5 like move this a little bit over here.
So I go over here. I have some text so there done and let's switch to count. So the count is 12.
That's what we expect. But now, if I rotate the rotate it. Note what happened to the mode.
It says, Please choose an analysis mode had a mode selected.
If I select uppercase, tell me 2 uppercase letters, too.
I turn it here, and I rotate it, and again it forgets the mode.
When I rotate. So my question here is is is simple.
Why, I just questions. Why does or 5 lose escape so it forgets the mode you're in when you when you rotate text analyzer.
So i'm just so here this so again, we'll also choose an analysis mode.
Go to uppercase. We wrote it, and it goes. forgets it.
But if we go over here, not just one cheer do I have My! This is the quiet here.
So here we tap along it forgets. the so it forgets a little bit, and we'll talk about how to we a couple of bugs here to deal with.
But here it doesn't matter that but it still remembers the number of times we click so that state gets preserved.
So. Yes, Kyle, Exactly. This is all about saved instant state.
So what's happening is is the running activity is destroyed So So anyone know what an activity is in android.
If someone's done. some reading ahead, we haven't discussed this yet, or know some background, So analysis function becomes we'll talk about what's Korean we'll talk about exactly what speak what's happening with the
app in a second So an activity is the unit execution and android app.
So there's a default activity when you launch. now. Well, it will a to be released sometime this week for the people to assignment.
2 is being graded Now I will check with yoking to find out what's when she should be able to get it done.
But I know she's working on it but so when you have multiple screens at an out. you can implement them as multiple activities.
You can do it as a single actor but so it's not really about splitting up the interface.
It's really what's splitting up functionality in the app So when we look at our code, there is all this stuff here, for you know there's all this activity terminology.
So you know, as we create a mid-class main activity, which is a type app compatibility. and so like that's use the organizing thing of our app, and that's a class.
And so that has state associated with it. We have this T.
And we have this, and we have this analysis result, and we have analysis, mode.
So note what is happening with this text analyzer app you're But we have this here.
This is, we have this t state which is the text that we've entered here.
So we have this text, Hello, the weave and and that's you know that's stored in t, but that t is an edit text.
It's actually a whole widget it's not just a string.
Then we have this mode here, which is a local string variable.
So when we rotate, the screen t retains its state.
But analysis, mode gets blown away because and so then, you and and so that's what's happening, though. is Oh, did I say?
Oh, so I say, t is a widget I Well, so when I say t is a widget.
What I mean is t is of type, Edit. text. What is edit, text, edit.
Text is this little you know when I say widget it's like this this little you know interface element.
That's why I went for a witch I really refer to an interface element.
So it's the edit edit text box it's not just the the string.
Yeah, it's a text field Yes, no no it's what specifically edit text that's what it's a type of it's of type edit text, and then when we but we don't say anything more about
that. Now I say, where is you know when I say Edit text, What is that coming from? That's coming from the Xml.
So if we go to the here this is where we've decided, declared edit text, we've put in this in the Xml.
This is the t here. So the layout creates this thing.
It has some state associated with that. This you know the input type text.
So it has taxed associated with it, and we can get it from it.
And in fact, we do that. we do that here when we want to.
Yeah, we'll run update analysis, we actually call school or something here.
We get the we get input text here by asking t it's text. So we're saying, No, this interface all this widget.
It's like, what is your tax associated with it and then we assign that to the local variable input tax.
We do it as a vow because it's equivalent to a let.
We're saying what's that value and then we're using that we have to convert it to a string, and then we use that to to display it.
So what's happening is so edit text it that class preserves its own state in some way.
I was going to show you how it does so but main activity Doesn't.
And so we have to implement that so let's look at what's happening with with tap.
Demo How does tap demo compare so let's look again?
We have. How does our main? What do we do when we create the activity?
We have this, you know, super on create you know safe safe instance state.
So that's like, Okay, that's doing something with saved instant state that just seems like boilerplate a little more than that.
And we'll talk about that we set content viewer r that layout activity main.
This is how we're specifying the xml file that's associated with activity.
Thing. The code is primary as opposed to the layout being primer as it is in Ios, saying, this is the layout.
We're using is activity main and Then Now we're have some other code to initialize things. So what are we doing?
We're setting up what t's value we're setting up what analysis, results.
Value is, and so t's value as we look in the view and find, you know, find the thing on the screen, and then we add this listener to it, so that when it state you know changes t watcher will be called, and then we set up
analysis result to be reference to the analysis result Widget: which we can.
Yeah, do we? we use analysis for Oh, yeah analysis result we use later, because that's how we put the result on the screen.
So we're we're setting up all these variables and then we call update analysis to make sure the know this, you know.
Choose an analysis mode thing is up is properly initialized.
The thing we've kind of have kind of glossed over here is a saved instant state and super on create.
So this is the basic idea here, is when your bundle is when your app is create, when the activities created it's past a bundle, you potentially, and if it's past a bundle there's like Oh, that was
your state, and when you yeah, and when you're about to terminate, you go like oh, I better save my state in in the bundle that's given to me, and pass that back and that in fact is exactly what screen
here that's exactly what tap demo does so notice here with tap, demo.
It still has this saved instance state bundle comes in and then it's a superong create saved inton state, and then it says, set content view.
That's all the same. But then, we say if saved instant state is not No.
So if we have some, you know some state, and then we, you know, use the with saved instance state, which is part of the bundle.
So this this just means that we can now access the properties of saved instant state without having to.
You know these parameters we have one that's in that called Count, and we, you know, so we have we have a key count here.
We look up in the and then we assign count to that value. So where's time to put data in and pull data out of these bundles at the right time. And the way you do this is by So on and on create we
take the saved and states past to us we Oh, sorry that's the wrong.
Just so here we get the, you know, same as they passed in to us.
We have to make sure we you know. call this super oncreate Sim State, because maybe someone else may need the bundle like our where we've inherited from.
So they we need to pass it on. So we have to call our a super class.
But then we can do something with it, and we can get the data out of it. now.
Weird how that data get in there because we overwrote saved in on safe instant state.
So whenever the Android frame was saying, you know you better save your data, because otherwise you may lose it.
So time to hit. save do this, and it says, you know, outstate run.
We do a put into, so does everyone. so all outstate, run.
What is that syntax get so that's just with oh, we're just passing it.
This function. we're just making a little function there it's like call that Do all this stuff, and then on this day, and then super, and then we call so on Instagram.
We first save our stuff, and then we call the super class to safe state.
Does this all make sense. What i've talked about here hello so i'm gonna Okay, i'm gonna move on here.
And let's talk about. So in order to know when these things are called, also have another thing happening here in this app is, we have logging happening.
And so this is this general facility, for seeing things so when you So if you go to large cat here, you can see the logs that are happening in the app and there's a lot of stats here that are put here, But you
can search this. so you put this here. We can search for everything with the tag.
Tap, Demo, and you can see all these things here. and notice here.
Now every time we do something here, so we're not getting a message there.
But notice what happens when we rotate? the right messages come through.
Yes, I think that was there, and then let's so that's 1211, 50 again.
I guess. I do there? Oh, wait, i'm running the wrong app so this is very irritating.
There we go It's Now here works out doing things here now we can rotate.
Let's rotate. Why, am I not getting the current log here.
These are old. Oh, that one's dead that's Why, I was looking at the wrong log output. So this is something to make sure is like which one are you looking at that was disconnected.
No, this is the one I want. This is the one here.
So now here I should be able to get as I do this we're getting nice little log messages rotate this here.
And so you notice here we got all these button, you know.
Paws stopped, save state destroyed, created, started, resumed.
Oh, well, that activity got destroyed so that one's dead I started to go back here. So you have so it's kind of annoying that you have to select.
So. Oh, here we go I mean that's why it's just regulars.
That's right that's fine there that works better no filters.
Let's make sure rotate. that yeah rotate here. So it's useful to figure out how to use this logging thing to make sure it does the right you know does the right thing.
There wipe their route button instead. of auto rotate. That's what what it defaults to There's a way to change it to auto rotate and I always forget how to do that If someone wants to remind
me how to do. Setup auto rotate is this similar to console Log in Javascript.
Yes, that's exactly. What this is this is the log and right now I've done this. but now if you want to find out what your are things doing.
There's all kinds of crap in this so I think what makes sense here is just to simply select no filters, because otherwise you're choose.
It's filtering based on which app and stuff and when you destroy things that just changes.
But if you need to, then say, Cap, Demo, whatever tag you use, and then you can just see the messages.
Your app is generating. but make sure that when you do this that it's generating the ones that you want.
Oh, it's probably because I now i'm using wrong want to keep.
Why has to keep doing that? know Why, anyway, there's some fiddliness, I think it's probably because i'm running 2 windows, and I probably should fiddle with that but the so we're getting these
messages. What are these messages actually mean? Well, these messages Are Is we are overriding?
So we've got these log messages throughout. you know longed d the dot d means for debug, and you give it a tag and a message.
Both are doing things. Yeah, Okay, So let me. This is main activity.
Dot. Okay, that's probably. Why, i'm running 2 windows i'm going to delete this one.
And then we can switch to So here's top demo here. Then we can focus on fixing this code you're gonna play with the other, you know, text analyzer 5 in the tutorial So we've got
we've override this unsafe instant state we put a log message there.
Then we've over it on destroy on resume on pause on start on!
Stop. These are all methods that are part of main activity.
We are doing anything in these except calling. the super one so we actually do the proper thing. you're supposed to do as opposed to eliminating that functionality.
And then we're calling the log so this is just showing you that you know, when these methods are called, and so one of the things that's useful to do is try to figure out what are these things called specifically what Oh, so
we talk about an activity, life, cycle in the sense of the creation, birth, death, and whatever.
So you should know. When are these things called and take the screen switch out.
So all these things you do in a mobile device when you switch apps, when you you know, terminate an app when you rotate the screen.
Those all those all show up to the app the app gets notices of it, and can't do things for it.
They might seem a little weird. Why is it terminating the activity when you rotate the screen? right?
So yeah, a log is a log is a method. Yes. Well, log is a function.
Yes, and those are other parameter. Do the specific app function concern the activity?
Lifecycle is what happens to an activity. The idea is the activity.
Things are being done to the activity, and it has to react to them.
The reason why an android activity terminates when it's rotated is interface.
You have to read it's a guy new gometry and you lay out and everything.
So when you do that, Miles will just kill it we started it'll know.
Okay, i've got a new new thing to do so it has to redraw itself.
Morning works, she starting a little bit, if we go to have some documentation here, the Android.
So this explains the concept activity we're going to talk about things like. So so I would say for right now, just talk read about the concept activities we're gonna talk about manifests and intent filters.
I'll try talking about that in a second here but that's not the emphasis here first.
I always want to talk about state and here's the android activity, lifecycle. and it tells you all the things of activity, launch, and it calls on, create, then on start and on resume and the activities running and then shut, down
prosecco. These are all this gives you a basic idea of and this Isn't, even the full.
This isn't even the full way the activity is run this is yeah, there's.
And so and so we're just defying these lifecycle callbacks to be called the event of different things.
This I feel like. if it feels a little unfuzzy, I think it makes much more sense.
Once you play with the app and kind of understand what's happening now in there's the same kind of thing is happening in Ios.
It's just it's a bit more automatic you don't have to.
You'll notice in our apps when we rotated them whether it was swift Ui or a storyboard.
We didn't have to worry about all of a sudden the apple losing state.
But it was redrawing the screen and stuff so I don't know we.
We are going to talk the details, but basically ios manages the stuff much more for you.
You don't have to think about it except if you want to do some.
If you want to have what you would normally expect for the app just to continue going, you don't have to think about it in Android yet.
You have you have to put more code in don't really know Why, you can't just defy default do some basic things, but it doesn't
Oh, yeah. So last thing I want to discuss is is there a way to get an on start without stopping the app. What do you mean?
I mean it's when you start yet when you first launch the app you should get an on start.
Now, what android does this stuff to you any time yeah when it's running what you why start is not something that you trigger it's something that's done to the app is that what you're so are you
looking for a way to test to trigger on, start as it as debugging.
Or are you saying in your normal app? Do you want to just call it?
Oh, like is a debugging. You want to reset the app.
Just relaunch it, or terminate and restart it like you.
Would any app on a device, you know? Yeah, I mean, just like on, you know.
You go to the task switcher and you terminate. Yeah, that terminates it.
Now, when you launch it, it's going to you're going to get non-start event.
But also yeah so it's Now you don't normally. you wouldn't call these inside your app you'd, or say up event handlers to handle things when these things are done to your app on start like there's if you look
at this it has there's subtle differences between these like, There's this is If you look through these things like concepts, So it tells you like, when on create happens like on start when the activity enters the start state
the system Invokes is called it makes the activity visible to the user, as the app prepares for activity and the foreground become interactive.
So on create is when you create it on start it's like Ok, now we're going to the user.
But the resume State has come to foreground. So this is you.
Switch between switch back to the app. It was running in the background.
It was, It had already been started. so you get an on resume event.
And so that's that's why, when we look at the messages here.
If you had a log cat here, you know. You see, we always always see weeks.
He created, then started, then resumed, essentially in scrape, one right after the other, you can, when you would just get resumed as if you had. Yeah, you switch quickly back to one other app and come back here you could do that, and
if for some reason your app took some time to initialize in the background, doing some things like that's when you might have some time between the and started.
But they really break this down normally. you don't have to think about it.
Only just think about created, and maybe on resume then i'll just, you know, maybe on destroy.
But again, with what are you gonna do there if you're using safe on?
If you override on safe instance, date, the framework we call that whenever it needs to be saved, whenever it's about to to lose state that will save it, you know I have to think about when in the lifecycle it's going to
happen. Yeah. is they say, nice to know, not signed to meddle with right? exactly.
Yeah, if you wanted to just reset your app state yeah you'd normally as a future, because remember, notice, it's happening in every part of the like different widgets of stuff will save their own state specifically so if you want to have more
of a global reset without terminating you up and restarting it.
Yeah, you'd have to manage your own state and go through it But let's go through here now, so what i'm showing here is that when we rotate the app you do this we get back to this you haven't tap
yet, so that's not right but it's not I mean I may look like the State has only preserved.
But no, the State has been preserved so where so let's look to see.
Where is that? Where is that message put so first we Look at activity?
Main and you see that you haven't tapped yet the default message on the screen.
That's what's put there you know that's what we put into the layout, and then when the mess the message gets in here.
Your click. This May Times is is done in my button.
Press. That's the only time where the clicking is put There is in my button press is not updated, so we restore the Count here, but we don't recreate.
This you click, count times. it's only going to get the text all going to be changed once you press the button.
So how should we restructure the code to to make this work as we would expect?
What do we need to do? we've seen this before so what you really want here?
He's, an we need to make a new method I should update Oh, I see.
Obviously update. we need a function update message and all the update message does is that's all it's going to do.
And then here, so there is a slight bug in this i'm going to show it.
But let's let's see if you all can guess what it is.
Go on. Okay. So he fixed it, But we change something we'll initialize you.
Click, count times. Yeah. So the thing is now is. It always shows the click.
But even when we first start the app, if we restart it, it starts off with you.
Click times. So it's always there well we really want though if we want to say, but you haven't tapped yet.
So that's let's go over Here What we really want to say here, is that all right?
So you have you have a tap yet? sorry. So now by adding this this thing here. Now we can go. okay. Now we go.
You haven't tapered that says you haven't tapped yet.
Rotate it this. So why is this worth noting? You know this?
This is a pretty simple thing, but just note the pattern of in order to make sure state of the interface reflects the state of the yeah.
The state of the interface reflects the state of the internal variables.
You have to have something that's synchronizes it. You have to have some code that that updates it, and you have to make sure that code is called in all the places that you need it to be called like it should be
called when you create, you know, when the screens created, and you need to know potentially do it.
Other times like when you change the state. Okay, so that's it for what I wanted to cover today.
I kind of want to make sure you all are up to date on tutorial, on tutorial 6, and you know, check that off and help you all with your android problems.
And then, because otherwise I need to start talking about intense, and I think we will talk about intense.
On Friday any last questions, Otherwise i'll end lecture here and we will, and i'll be here for checkoffs.
Okay, so that's what I I will help with so I was saying, Hey, I'll stop much here, and cannot if you don't have a checkoff to do today.
Then, or you don't want to get help You can head off, and I will see you on Friday.