You are on page 1of 9

[MUSIC] Well, hello.

In this video we're going to play with the Android emulator and I'm going to show you, uh, some tips and tricks that we can do with it. But, uh, first of all let's just have a bit of fun. We've got two of them running, so why don't we send a message from one to the other. Ah, let's start, uh, messaging, on this emulator. Okay. And, uh, we'll write a new message. Okay, so to, who should we send it to? Well, for this, we need to know the, uh, how to send it to the other emulator, and the trick to know is that, uh, we're going to use this number up here in the title bar, so you'll see that we have the name of the emulator instance but also this number this 5554. In fact the first emulator that you start will always have the number 5554. Ah, the second emulator will have two more than that, so 5556. The third emulator h-if we had a third one running, would be 5558, etcetera. You can have up to 16 emulators. I've never run 16 at a time, but I'm sure someone in this course will tr-will try to. So, let's, uh, send a message to 5554, and we will say, "Hi," okay, right, "let me out I'm an emulator," or something like that. So we'll click the Send button. Okay, so this number, this 5554, is a port number. Now what is a port? Well, just like, uh, when you dock a ship at a port, it's a way for us to connect to, uh, programs which are running on a computer. Ah, okay, let's start this up. Oh, look, we have a message. There we go. So we have a message from 5556, the other emulator. And we could respond to that, and, uh, so-and text message, uh, each emulator fo r free. Uh, so, the next segment I'm going to show you is that, uh, the emulator, in addition to supporting the, uh, keep the hardware keypads over here, so, here we are; we have some buttons like the home menu, ect-the home, for example. Um, we can also control, uh, whether the emulator is in landscape or portrait. So, uh, let's do that. So on a, this Mac I'm going to press Ctrl and F11. Ah-ha! And it's flipped over, and it, uh, restarts the home screen, ah, in its, ah, lan dscape mode.

Now, why is that useful? Well, the answer is that, behind the scenes, um, when a phone call comes in or when the user flips the phone over to its side, uh, the system does quite a bit of work and your app may have to do quite a bit of work as well. Perhaps it has a different layout, uh, ah, configuration. And so being able to test it on the emulator, uh, is an important part of getting your app ready for publishing. Right, so we can flip it back. Ah, ah, one surprise, uh, I had was that, uh, you've got to release both the Ctrl key and F-F11 for this to work. Uh, I'm holding down the Ctrl key now and pressing it multiple times does nothing. It, it, it ignores the function key until I let go of, uh, both the Ctrl key and F11. So if you're wondering why it's not working, why it can't flip, make sure that you let go of both. Okay. Let's pop it back. Now there are other keys as well, and I'll show you later on in this video the, the link for that. Uh, right now, uh, let's, um, show you the secret, uh, the, uh, secret way into the emulator. Um,and for that we are going to need to connect to this, uh, port number, this 5556. Uh, and then we can start talking to the secret interface, if you like of the, of the emulator. For this, uh, we'll use a, uh, an old tool called, uh, Telnet, uh, which allows us to type commands directly, uh, and connect to a particular port on a certain machine. Right, so, on a Mac how do we do that? Well, first of all we will start a terminal, okay. Ah, so this is our terminal instance. And I can now type telnet, and connect to somewhere. For example, let's have some fun, let's connect to the BBC. Hey, BBC, bbc.co.uk. And if I was a, uh, web browser like Firefox, Safari, Internet Explorer, by default I would connect to port 80. So let's connect to port 80 on that machine. So, I've now connected to a distant

machine over in the UK, and here's where I would request a particular webpage, um, so I would, there we go. Uh, I was not fast enough; let's try it again. Uh, let's connect here and, type some gibberish. And I guess what the, the server, uh, the BBC server did not like my, my, my gibberish and said, hah, I do not understand. So it, um, it responded with, "Hey 400, bad request" and sent the client sent a bad request and closed the connection on us. Um, so if we were a more polite, uh, web client, we would of course, uh, would've sent the correct, uh, codes to request a particular, uh, we b page, and we would, and the server would have sent back information, or sent back, uh, an image, or sent back the text of the web page. Uh, right, now we've finished, uh, playing at the BBC; Let's, uh, connect to the, ah, emulator. For this we need to know where it is and which port number. Uh, so it, it's, uh, on the local host so, I do telnet space localhost and Port 80. But wait, what if you are a Windows user, ah, how do you get, ah, telnet? Well for that you might start by googling, uh, How to start telnet on Windows. And, uh, here's a web query I performed earlier; here it is. And you discover that on Windows 7 and Windows 8, uh, you have to jump through some hoops first to reinstall, uh, telnet. It's no longer available by default. And here's the steps you'll need to go through. You'll need to open the Control Panel, ah, find Programs and Features, and, and then look for Windows Features, ah, and then, fe-, inside Windows Features you'll find a checkbox for the Telnet Client. So, clicking on that will af-, and then clicking on OK, will re-install, ah, ah, Telnet client for you. Right, so now you've got telnet, um, what do you need to do to start it? Um, I-, you have a Start menu, uh, enter Cmd, so this is, uh, Windows equivalent of me typing, uh, terminal in my Mac. And once you're inside the, ah, command window, ah, you can type telnet. Now these instructions suggest just you simply press Enter, but, uh, rather than do that, ah, you could actually, ah, specify the, uh, machine that you want to connect to and the port number, as we did over here. So, we are going to connect now to, uh, it's, uh, there we go, uh, local host port 80. Right, so let's do this. Um, but we don't want port 80. We want a different port. We want to connect to the emulator, so let's connect to, uh,

either 5554, the first emulator instance, or my second emulator instance 5556. Here we go. All right. We are in. We are connected. I'm now talking to, uh, the emulator. I'm talking to the Android console that's, uh, behind this emulator. And, uh, very helpfully it provides a little help menu so I can type help and get a list of commands. Uh, so one of the useful commands is, uh, I could, uh, send a text message, an S MS message, so let's send an SMS message to, ah, this Android instance, and we'll say this message is from, let's say, 787, and we'll say Hello Emulator. Woops. I didn't get the syntax right. Well, we forgot to send, ah, sms send, and then we need to say who it's from, so 787 blah blah blah. And we'll say, Hello! Okay. Back on this side we'll see at the top here we get, a little message appeared at the top. And if I pull this down, there it is, I've got it there. Okay, let's pull it down. I've got my little hello message. All right So now I could write and test apps that respond to text messages and test them inside the emulator. Uh, I can also from, uh this con-, this, the console, ah, control what the emulator thinks the battery level is doing, so right now, it thinks it's at 50%, and over here, after that message disappears, you'll see it's, uh, showing that it's connected. It's recharging, and it's recharging from 50%. So let's, um, change that. Right, so I will do help power, and we can do power change the capacity to say zero. Ah, okay, and you'll see now in our little window, absolute, oh, okay. Message disappears that it's actually recharging from zero. Ah, so again, we could, uh, test our apps easily which respond to power messages. Another useful thing we can do here is to change the window scale. So if I do help window, we'll see that we have one command called scale, so let's make it a smaller window, say 0.5.

And we have a little window somewhere. Where have you gone. There. Uh, you can try to make the scale, ah, larger. In practice I've found this is, a, a, ,a, a easy way and fast way to crash the emulator. Uh, and then one final thing which I've, uh, often used is the, the avd command to temporarily pause the execution. So, um, in avd, you'll see there's a start and stop command, so I can do avd stop, and this has paused, uh, the emulator, so it's not going to respond to any events right now. Uh, this is, uh, useful if I'm running my laptop without power, and this cuts the amount of power used by the emulator by about half. It's still using some CPU power, even though we've, we've asked it to stop. Um, but it's a useful trick if you're, if you're trying to make your, your own actual laptop battery run for as long as possible and you don't want to quit the emulator. Okay, so let's, uh, start it again. Okay, you'll also notice there's a snapshot interface there and you can use that to, uh, save snapshots and, uh, d-, list snapshots. Uh, this is a way so you can, ah, restart your emulater instance from a particular known state, perhaps, uh, with a couple of applications already ins talled. That kind of thing. This is, this is kind of fun. Let's, uh, let's, uh, let's call our, our emulator. So, into the gsm menu, discover that we can [laughs] call it. So all right. Hey, well, we better give it a number that we're calling from, so there we go. And. [pause] Our phone, somebody's calling our emulator. Unfortunately the emulator doesn't, ah, fully support voice calls, and we can't make real outgoing calls, but again, this a way to be able to test our apps that might respond to calls. Also, Android will, um, pull the rug out from underneath running applications when the phone is running. Ah, a lo-, a lot of behind the scenes works. Ah, a lot of behind the scenes functionality happens that the user doesn't realize where and the Android operating system will temporarily put an app on ice, if you like, and then restore it later, um, just in the same way that on a stage, ah, the actors might disappear during the interval and then when we pull back the curtain again all of the actors are back in

places, and the scenery is back, and the props are ready. Ah, Android does the same thing with apps in order to manage the very limited resources that a phone has. Okay, so, uh, let, we'll cancel the call, um, right. And we need to give it the number again, 6754321. Ha, and we hung up on the emulator. Okay, so that's it for now; you've watched me play with the emulator. Now it's time for you to, to learn how to use these emulators, so, um, let's see. I, go to Google Chrome. I want to show you two things on the, um, developer website. Uh, first of all is, uh, where can I find the instructions for the, the keyboard shortcuts. Uh, they're not immediately obvious. They are actually just a, a little lower than you might expect. Here I am on the developer.android.com, and, um, the last section on the left, uh, left here is, um, we've gone down past Download, we've gone past Workflows, we're past Support Library. Inside Tools Help, uh you'll find in here the emulator. And this lists the keyboard shortcuts, uh, that you can use. And like I say, the most useful one I find has been the ability to swap between different layout orientations, either the portrait or landscape. So, uh, make sure you practice that, and also see if, uh, full screen, Alt+Enter works on your system as well. And finally, let's, uh, talk about the speed of the eliminator and what you can do to speed it up on your system. So, um, if you're lucky you will be able to get the, uh, Intel accelerator technology working for you. A word of caution though at this point. At this moment in time, uh, uh, Apple ha s just released a maverick, and the current available version of the, ah, technology accelerator, the accelerator technology does not work well with Maverick. Does not play well. So, hopefully by the time you look at this, um, if you've got Maverick installed, then the HAXM technology will have been updated. If you cannot use the HAXM technology then I encourage you to play with both the arm emulator and the Intel, ah, emulator, to see one, which one is faster for you. You may find, as I did, ah, that the latest emulator is a little bit slower than the earlier ones.

Um, so, if I just, ah, talk about timings for a moment. Okay, where is my... Here it is. Okay. Ah, if I just talk about, uh, timings for a moment. Uh, let's see what we've got. Um, I, I tried with four different instances here, so we have the early versions of Android, the, uh, level 10. Here we go, the API level 10, and I tried starting up the emulator in both the arm and Intel, and both of these took, uh, 30 seconds. So, a little bit slow, but once you've started up you can keep uploading new versions of your app to it and so that's, ah, not, not, not too terrible. And as you saw, the emulator was, was, was, ah, useful. On further, more modern operating system, ah, ah, things are a little bit slow without the accelerator, so the, the ARM one was, ah, 75 seconds. [pause] The Intel was 135 seconds. And, very slow. So almost, ah, unusable. Um, so if you don't have, uh, accelerator technology, you're going to, to find it an extremely frustrating, ah, experience to try to use the latest Intel, ah, ah, ah, emulator. Right. So let's see what happens if we, ah, do install the, the technology accelerator. All right. So, that's, out of this. Right, how do we do that? Well, a reminder that we used the SDK manager. And, ah, this tool allows us to configure which compartments we have, ah, locall y. So let me, just look at the things I've got installed. And you'll see underneath the extras, ah, I have the Intel x86 Emulator Accelerator or HAXM. This, um, only, ah, accelerates the Intel images, not the arm images. And its revision is, ah, revision three, so if you're looking at revisions four, maybe that will be working, ah, well with, ah, Maverick. Okay, so, l-let's go and have a look at that. We've downloaded it, we've installed it, according to this, but actually we haven't yet run it, so I need to go and look at the SDK here. So we go into Extras and Intel, and here is the hardware accelerated execution manager. And on a Mac, we have a disk image file. Let's open this. You'll have a similar file in Windows.

And, ah, notice that even though, ah, Android thinks it's version 3, Intel calls this, ah, version 1.0.6. So let's open this and just run through the installation procedure. Ah, here's a surprise. We have to make a choice about how much memory to give the acceleration. Ah, my machine has eight gigabytes. And, I need some of that obviously for the operating system, some of that for Eclipse. Ah, I'm going to have to put aside some of it, ah, every time I want to run these hardware accelerated managers. The total amount I'm going to put aside is for all emulators that are running at any one time. Now normally I just have one emulator running. Ah, what I found is with a emulator the Nexus 4 is that I can ump down the actual amount of RAM I give it, say, from 1900 to about 1500, ah, and then that comfortably fits inside, um, the Intel limit here that I'm going to give the accelerator of say about two gigabytes or 2048 megabytes. Um, so this memory allocation, I mean I'm choosing to take away from the best of my system. So you have to try and find a, strike a balance, with, with what memory have on, ah, your, your laptop, or your, o-or your system so that you have enough memory to run Eclipse. And the, the, other tools. Um, so ideally you have at least, uh, a four gigabyte machine. Right, so let's go with 2048. If you, um, decide to play with this value, all you need to do is, uh, run this, um, installer again. And then you can, ah, change the, ah, the amount of memory that you've given the accelerator. Okay, so that's installing. Ah, it's not going to take five minutes; it's going to be quicker than that. And, let's, um, go back to here. Right, I should mention how we, we, we, ah, close our emulators. You could click the power button but that doesn't actually, ah, stop them. It's, ah, it's easier to turn them off, just close them. Okay, right, so how's the Installer doing? Right, once this is installed, ah, we're going to try, ah, running one of the em ulators again just to see what kind of speed-up we get here. Okay, I need clips.

And go to my Android Virtual Device Manager. Ah, let's start the Intel at level 10. Launch. [pause] It's working and the emulator is running in fast vert mode, ah, so now we should, ah, see an emulator that is, ah, fairly speedy. Here we go. And, uh, uh, uh, almost a joy to, to, to develop one. Okay, so that's, uh, everything we're going to say at this point. I'm going to f-finally mention that you'll probably run into an issue or two. Ah, maybe these, uh, this video has become a little bit out of date, etcetera, so do be sure to check the, ah, Coursera discussion groups. And also if you have a specific problem, ah, try to find out as much as you can about your system or the error message, and then become a detective. Use Google, use discussion groups, etcetera to perhaps try and find someone that's had, run into a similar problem as you, and see how they solved it. Right. That's it for now. Uh, time for you to, ah, play with your emulators and find out what works on your system. Bye.

You might also like