The best way to test your app is by using a real device. The Android emulator is pretty slow and does not provide you with all the features that come with a real device, such as a camera and all kinds of sensors.
I can image that you do have just one or perhaps a few devices. With thousands of Android devices being available and many brands and models that run on a customized (for example, the Samsung devices) or a plain (like the Nexus devices) flavor of the Android OS and on any Android version that you can think of, testing on real devices only would become pretty expensive.
If, for example, you are creating an app that should run well on Android 2.3, Android 4.x, and Android 5.x, using emulated devices can be handy. Unfortunately, the default emulator is terribly slow. It takes ages to start Android on the emulator, and debugging can be very slow on it as well. To make the emulator a little bit faster, you could try to install Hardware Accelerated Execution Manager (HAXM). There are some topics on the Internet that tell you how to do this; however, there is a much better solution, Genymotion.
Genymotion is a real, fast, and easy-to-use emulator and comes with many real-world device configurations. You can read more about Genymotion on its website at www.genymotion.com. It is available as a free or paid solution. The free one will be all right to start with.
Make sure you have Internet access and sufficient space on your hard drive. We will need to download both VirtualBox and Genymotion. After this, you are ready to create your first virtual device. Let the magic begin.
Let's install Genymotion to prepare Android Studio to work with smoothly running emulated devices:
Download VirtualBox for OS X hosts (or for Windows) from the VirtualBox download page at https://www.virtualbox.org/wiki/Downloads.
Install VirtualBox, and after that, reboot your computer.
Download Genymotion from its web page at https://www.genymotion.com/#!/download.
And it is running fast and smooth! Pretty cool, isn't it?
The following is an example of the main screen of Genymotion listing a couple of virtual devices that have been created:
Genymotion comes with emulated front and/or backend cameras, depending on the chosen configuration. To enable them, click on the camera icon. A new dialog box appears in which you can change the slider to On and choose a real camera for the front and backend camera of your virtual device.
After selecting a camera, you can close the dialog box. A green checkbox will now appear next to the Camera button. Now, whenever an app needs to use a camera, it will use the selected camera, which in my case is the webcam on the laptop. To check whether this is working, choose the Camera app on the virtual device.
The paid version of Genymotion has additional features available, including emulated sensors such as GPS and accelerometers. If you like, you can check out the differences at https://www.genymotion.com/#!/store.
Remember that although using virtual devices for testing purposes works really great with Genymotion, it is important to always test it on multiple real devices. Some issues, in particular the ones that are related to memory management that we will see later in this book, are easy to reproduce on real devices, but may be somewhat harder to reproduce on virtual devices.
In addition to this, real devices are much more pixel perfect and some issues may appear only on a particular device so when it comes to see how the artwork looks, you are going to need a couple of them.
By the time your app is nearly complete, you might be interested in the (paid) services from Testdroid, a cloud-based service that allows to run (automated) tests on many real devices. Visit www.testdroid.com to learn more about this great service!
The following screenshot provides an example of the Hello Android Studio app running on a virtual Nexus 5 device using Genymotion: