The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Advanced Emulator Capabilities

The Android emulator, at its core, is not that complex. Once you have one or more Android virtual devices (AVDs) defined, using them is a matter of launching the emulator and installing your app upon it. With Android Studio, those two steps can even be combined — the IDE will automatically start an emulator instance if one is needed.

However, there is much more to the Android emulator. This chapter will explore various advanced features of the emulator and how you can use them.

Prerequisites

Understanding this chapter requires that you have read the core chapters of this book.

Other Notable Configuration Options

When defining an AVD, or editing an existing AVD definition, there are many other configuration options at your disposal.

Hardware Graphics Acceleration

Another way to speed up the emulator is to have it use the graphic card or GPU of your development machine to accelerate the graphics rendering of the emulator window. By default, the emulator will use software-based rendering, without the GPU, which is slow in general and worse when running an ARM-based image.

Whether this will work or not for you will depend in part upon your graphics drivers of your development machine. Also, their use might conflict with other things you might want to do — on Linux, using hardware GPU mode might break your ability to take screenshots, for example.

This setting is toggled within the AVD Manager, for new and existing AVDs, via the “Graphics” drop-down list in the “Emulated Performance” group:

Virtual Device Configuration, Showing Use Host GPU Checkbox
Figure 935: Virtual Device Configuration, Showing “Use Host GPU” Checkbox

There are three options:

Keyboard Behavior

The Android emulator can emulate devices that have, or do not have, a physical keyboard. Most Android devices do not have a physical keyboard, and so the emulator is set up to behave the same. However, this means that typing on your development machine’s keyboard will not work in EditText widgets and the like — you have to tap out what you want to type on the on-screen keyboard.

If you wish to switch your emulator to emulate a device with a physical keyboard – either “for realz” or just to simplify working with the emulator on your development machine — you can do so.

In the Android Studio AVD Manager, in the “Advanced Settings” area, there is an “Enable keyboard input” checkbox that determines whether hardware keyboard input is honored in the AVD or not:

Virtual Device Configuration, Showing Enable keyboard input Checkbox
Figure 936: Virtual Device Configuration, Showing “Enable keyboard input” Checkbox

Startup Settings

Pixels on your development machine’s monitor probably are substantially larger than the pixels on most Android devices. If the emulator tries to use one hardware pixel on your monitor for every emulated pixel of the device screen, your emulator may be bigger than your monitor can fit. The “Scale” drop-down controls how the emulator scales its output to deal with your monitor. “Auto” — the default value — probably is your best option, though you are welcome to use one of the other options to control the scaling more directly (e.g., 4dp on the device maps to 1px on your monitor):

Virtual Device Configuration, Showing Scale Drop-Down
Figure 937: Virtual Device Configuration, Showing “Scale” Drop-Down

You can also control whether the device starts up in portrait or landscape mode at the outside, by the toggle buttons labeled “Orientation”.

Note that scaling and orientation can also be controlled while the emulator is running; these settings merely control the startup conditions.

Camera Options

In the “Advanced Settings” area, you can control whether or not the emulator emulates a device with a camera:

Virtual Device Configuration, Showing Camera Options
Figure 938: Virtual Device Configuration, Showing Camera Options

Whether you can configure both front and back cameras, or just one, is indeterminate. If you can configure a camera, your options are:

However, the emulator’s ability to truly emulate the way Android cameras behave is very limited. Serious camera testing needs to be done using Android hardware, not the emulator.

Memory and Storage Configuration

In the “Advanced Settings” area, you can control how much RAM and storage is used by the emulator:

Virtual Device Configuration, Showing Memory and Storage Options
Figure 939: Virtual Device Configuration, Showing Memory and Storage Options

Specifically:

Usually, the defaults are fine.

Frames and Skins

By default, the emulator appears in a bare window, showing the contents of the “touchscreen”. Of course, an actual Android device will have more around it, such as bezels, optional hardware buttons, and so on.

In the “Device Frame” group in the “Advanced Settings” area, you can check “Enable Device Frame” and choose a skin to wrap around the touchscreen and make your emulator look a bit more like a real device:

Virtual Device Configuration, Showing Device Frame Options
Figure 940: Virtual Device Configuration, Showing Device Frame Options

The Emulator Sidebar

The preview of this section was the victim of a MITM ('Martian in the middle') attack.

Emulator Window Operations

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Headless Operation

The preview of this section was lost due to a rupture in the space-time continuum.