Lesson 0.6: Running an Android app in a virtual phone or tablet
We have our first app (displaying Hello world!) without coding anything. Before we start developing something more, let’s check how this simple app works. This is very easy – we will use built in emulator of a mobile device. The emulator is a special application which would simulate a real Android device (including original system behavior and hardware behavior) on a computer.
It’s not 100% perfect, but it’s the only way to test your app on most typical devices without having them physically. You could imitate both smartphones and tablets with various equipment and system.
Step 1: Choose Run | Run ‘your app name’ from menu or just press Play icon in submenu (it could take a few second at the first time).
Step 2: In the window Choose Device we have two options: Choose running device (this is for real devices) and Launch emulator which would simulate a device on your computer. To use emulator first we have to create virtual device. So click an ellipsis button (three dots) next to the yet empty list of devices.
Step 3: We have opened Android Virtual Device Manager which allows to create many different virtual smartphones and tablets. At the moment we need just one so click New.
Step 4: In window Create a new Android Virtual Device (AVD) you have to fill a name of device and choose its size and resolution from Device list. It’s good practice to write as a name a type of device, screen size in inches and screen resolution, for instance Smartphone_4_480_800 (mind that only some characters are permitted in a name). For some devices from the list you have to set Target as well (Target is a preferable version of Android system) – choose the highest (newest) available. The rest of options leave as they are. Click OK. There would be summary of created device. Click OK.
Step 5: Now you see your virtual device in Android Virtual Device Manager – you could close that window. Go back to Choose Device window and choose the device you have created and click OK.
Step 6: Virtual smartphone is starting. Depending on your computer performance it could take a few minutes. Wait until you will see your app on the screen.
By the way – there is now a new window opened at the bottom of Android Studio that so messages related to run process, but we don’t need it now.
Step 7: You could use emulator as a real device. If you click Home button in the right panel of virtual phone you will see the main screen of the device (at the first time you will see some extra instructions). Now click Apps icon on the screen and you will see grid of installed apps including your app. Click it and you will open it again.
If you want to see your app running on tablet, just create another virtual device. Keep in mind that tablet emulators uses even more of your computer resources so rather for simple testing basic apps it’s better to use smartphone emulator.
It’s useful to keep emulator running when you still improve your app. If you introduce some changes in the app, just click Run again. New version would be upload to your emulator and started. It’s much faster than starting every time an emulator.