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 may 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.
If you don't see the above dialog box, then you can select a device from the dropdown list to the left of the Run button:
You can create a new Android Virtual Device by clicking the button Create New Virtual Device, or the item Open AVD Manger from the above list. When you do, you'll see a screen like this one: (Later Versions of Android Studio will see a different screen first. Click the button in the bottom left that says Create Virtual Device.)
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:
In the image above, we've selected Nougat at the top. You need to select something here, otherwise you'll get an error at the bottom of the screen and you won't be able to click the button at the bottom to continue. If there is no item to click, select one of the download links. Android Studio will then update your software.
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. If you don't see this dialog box, you should see your new virtual device on the dropdown list to the left of the Run button.
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 take 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: (Newer versions if Android Studio will have the real device already selected in the dropdown to the left of the Run button so may not see this dialog box.)
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. (Sadly, newer version of Android Studio don't have this information.)
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.