To run an app in Android Studio, you can click the green arrow in the menu bars at the top:
Or you can click the Run menu, then select Run (we've cropped a few items from the menu below):
When you click on Run, you will be asked to choose a device:
As you can see, we don't have a real device plugged in to this computer, as it says none under Connected Devices. (We'll plug a real device in, soon.) There is an option under Available Virtual Devices, however. For us, this is Nexus 5X API 25 x86.
You can create a new Android Virtual Device by clicking the button Create New Virtual Device. When you do, you'll see this screen:
Click a Category on the left. We've selected Phone. You'll then see a list of pre-set specs for this hardware. We've selected the Nexus One, which has a screen size of 3.7 inches, and a resolution of 480 by 800.
You can also create a new hardware profile by clicking the button in the bottom left. You'll then see this screen:
But going back to the Select Hardware dialogue box, and our new Nexus One Android Virtual Device, click the Next button to see this screen:
Accept the default, and click Next. You'll see this screen:
Again, leave these settings on their defaults. Now click the Finish button at the bottom. You will be returned to the Select Deployment Target dialogue box where you will see that your new virtual device has been added:
Select the device and click OK on the dialogue box. Your virtual device will start up.
Running your apps on a virtual device is a lot slower than on a real device. It can a considerable amount of time, in fact, before the apps loads!
The first thing you'll see is a message at the bottom of Android Studio. Something like this:
Eventually, you'll see the emulator appear:
You may see this screen for some time, depending how fast and efficient your computer is. On a slow computer, you can probably go out and do the shopping right now. By the time you get back you may, just may, see a screen like this:
This is a virtual version of the Android operating system. The final step is for your app to display. It should look like this:
And there it is - your app running on an Android Virtual Device! The text from the TextView control is Hello Android World, and is displayed on a white background. The Hello Android World in white text on a blue background at the top is the app name, and is coming from somewhere else. You'll see how to change this in a later tutorial.
But have a look at the control strip to the right of the emulated phone. This one:
First of all, DON'T click the X in the upper right corner. This will close
down the AVD, and you'll have to start it up all over again. You can click the
minimize icon just to the left of the X, though. Also, don't click the power
button, either, as this could lead to a black screen on the deice inside the
Try clicking on some of the other icons, however, especially the rotate left and right ones.
Testing on a real device
We recommend testing on a real phone or tablet. The Android Virtual Device gives a good impression of what your app will look like, but it's not perfect. There's no substitute for plugging in a real device into your computer via a USB micro cable.
When you do plug a real device into your computer, click Run again to see the dialogue box appear:
The connected device is a Samsung Galaxy S6. Notice that it tells you the maximum API number that this phone supports, which is API 23. So if you're not sure which API number your device supports, plug it in to your computer and have a look at the Connected Devices entry.
Select your phone or tablet from the Connected Devices section. Click OK on the dialogue box and you should see the Hello Android World app appear on your phone/tablet.
Stopping your apps
To stop your app running and return to Android Studio, you can click the stop
icon at the top:
You can also click the Run menu, then select Stop app:
A shortcut is to hold down the CTRL key on your keyboard and then press the F2 key.
Now that you have some idea of how to create and run apps, we'll start to explore in more detail. First up is Layouts.