5 minutes read

In the previous topic, you have learned how to create a new project. It is not enough to just create it, though: you probably want to run and test your new app as well. In this topic, we will go through the ways you can run your app with Android Emulator or on a physical device.

Android Emulator

Android Emulator is a special tool used to emulate a real Android device. It is fully capable of running apps and it allows you to test your app on a variety of Android versions, screen sizes, states, and so on. The Emulator has almost all the capabilities of a real Android device.

One thing to keep in mind is that despite all the benefits that the Emulator provides, it can be slower than a real device.

Virtual Device is a configuration that defines the characteristics of your Android Emulator. The Device Manager is an interface you can launch from Android Studio that helps you create, launch, and manage the settings of your device. Among other properties, Manager contains an Android system image, hardware settings, and skin — the frame of an Android phone you see while using the Emulator.

Creating and running a new virtual device

To create a virtual device, select Tools → Device Manager, or find the Device Manager tab on the right side of your Android Studio screen with a project open (near the Editor Window). The Manager will show up and you will see the button that says "Create device". Click that button and you will see the list of hardware options to emulate:

Select hardware window

For example, let's choose Pixel 3. If you look closely at the picture above, you'll notice that next to some devices there's a small Play Store icon. If you choose a device that supports Google Play Services, you will be able to download apps from the Store and test certain features that require Play Services.

After choosing the hardware, you need to choose the API version from the list of available versions. By default, Android Studio shows you the list of recommended Android versions. If you need an older system image, switch to "Other images". Make sure that you didn't choose a version lower than the one you've selected when creating your project; otherwise, your app will not install.

You're almost there: now give your device a name, double-check that all the selected options are correct, and hit the "Finish" button. If you want to be more meticulous about the settings, you can click the button "Show Advanced Settings". There, you can change the amount of RAM available for the Emulator, network latency, Emulator storage, and more. You can always change these settings later in your Virtual Device settings.

That's it! Now you should see your new virtual device in the Device Manager. Click the green triangle button and give it some time to initialize.

Emulator features

After the Emulator has started for the first time, you can switch back to Android Studio and run your app. To do this, choose your virtual device in "Available devices" and press the green "Run" button which is located in the toolbar in the upper right corner of your window. Give the Studio some time to build the app, and you will soon see it open on your emulated device.

Let's take a closer look at the Emulator features.

Emulator inside Android Studio

You can use the emulated device almost the same way you would use your normal phone, so everything should be pretty intuitive. You will also see a row of little buttons next to the Emulator. In this bar, you can lock or shut down your emulator, control the volume level, rotate your virtual device, take a screenshot, zoom in your screen, and simulate standard Android buttons like "Back", "Home", and "Recently opened".

If you click on the three dots at the end of the buttons list, you will see some additional settings:

Extended controls for virtual device window

Extended controls allow you to simulate various conditions that can happen with the real device: different poses of the device, battery levels, GPS location, incoming calls or text messages, testing Google Play Services, using camera and microphone, and others. All of these allow you to extensively test the app features that can't always be tested on your real device.

If you're working on a simple app, you may not need all of these features.

Running the app on a physical device

To run your app, you will need to enable Developer options first. To do this, search for "Build number" in your settings. The build number location may vary depending on a phone brand, but it is usually not hard to find.

Here is how you can do this on some popular modern Android devices:

  • Google Pixel: Settings > System > About phone > Build number

  • Samsung: Settings > About phone > Software information > Build number

  • LG: Settings > About phone > Software info > Build number

  • OnePlus: Settings > About phone > Build number

  • Xiaomi: Settings > About phone > MIUI version

As you can see, the process is almost identical for different brands. Once you have found the Build number, tap it 7 times, and you will see a little pop up saying "You are now a developer!". If you have a password set on your device, you may need to enter it.

Now, we need to enable USB Debugging. Go back to the Settings and scroll down until you see "Developer options" as an entry. Click it, find "USB Debugging", and turn it on. Plug your phone in your computer, click the green "Run" button in the Android Studio toolbar, wait a bit, and you will see your app on your real device.

Conclusion

In this topic, you have learned how to run and test your application on a real or an emulated device. Now you should understand the difference between Android Virtual Device and Android Emulator, their possibilities, the features that can help you emulate different conditions, and the ways to run your app on real devices.

112 learners liked this piece of theory. 2 didn't like it. What about you?
Report a typo