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.
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.
Understanding this chapter requires that you have read the core chapters of this book.
When defining an AVD, or editing an existing AVD definition, there are many other configuration options at your disposal.
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:
Figure 923: Virtual Device Configuration, Showing “Use Host GPU” Checkbox
There are three options:
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:
Figure 924: Virtual Device Configuration, Showing “Enable keyboard input” Checkbox
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):
Figure 925: 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.
In the “Advanced Settings” area, you can control whether or not the emulator emulates a device with a camera:
Figure 926: 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.
In the “Advanced Settings” area, you can control how much RAM and storage is used by the emulator:
Figure 927: Virtual Device Configuration, Showing Memory and Storage Options
mksdcardto create your own disk image that you attach to the emulator.
Usually, the defaults are fine.
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:
Figure 928: Virtual Device Configuration, Showing Device Frame Options
The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.
The preview of this section is [REDACTED].
The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).